import React from 'react';
import {Link} from 'react-router';

var PortalSidebarAdmin = React.createClass({
    displayName: 'PortalSidebarAdmin',
    propTypes: {
        routes: React.PropTypes.array
    },
    render() {
        return (
            <div>
                <ul>{this.renderRoutes(this.props.routes[0], '')}</ul>
            </div>
        );
    },
    renderRoutes(item, fullpath) {
        if (item.childRoutes) {
            if (item.path) {
                return <li key={item.path} style={{marginBottom: '.5rem'}}>
                    <strong><Link to={fullpath}>{item.path}</Link></strong>
                    <ul style={{marginLeft: '.5rem'}}>
                        {item.childRoutes.map(ii => this.renderRoutes(ii, `${fullpath}/${ii.path}`))}
                    </ul>
                </li>;
            } else {
                return this.renderRoutes(item.childRoutes, fullpath);
            }
        } else {
            if(item.path) {
                return <li key={item.path}>
                    <Link to={(item.path.substr(0,1) === '/') ? item.path : fullpath}>{item.path}</Link>
                </li>;
            }
        }
    }
});

module.exports = PortalSidebarAdmin;
