/*
Navigation Menu

@copyright (c) Copyright 2013-2017 Dorian Pula
@license AGPL-1.0
@author Dorian Pula [dorian.pula@amber-penguin-software.ca]
*/


import {h, Component} from 'preact';  /** @jsx h*/

import {Link} from 'react-router-dom';
import PropTypes from 'prop-types';
import {Nav, NavItem, NavLink} from 'reactstrap';


class NavigationMenuItem extends Component {
  static get propTypes() {
    return {
      title: PropTypes.string,
      url: PropTypes.string
    };
  }

  render() {
    return (
      <NavItem>
        <NavLink>
          <Link to={ this.props.url }>{ this.props.title }</Link>
        </NavLink>
      </NavItem>);
  }
}


class NavigationMenu extends Component {
  static get propTypes() {
    return {
      menu: PropTypes.arrayOf(
        PropTypes.shape({
          title: PropTypes.string,
          url: PropTypes.url
        })
      )
    };
  }

  render() {
    let navigationMenuItems = [];
    for (let menuItem of this.props.menu) {
      let menuId = `${menuItem.title.toLowerCase()}_${menuItem.url.substring(1, menuItem.url.length)}`;
      let menu = (
        <NavigationMenuItem key={ menuId } title={ menuItem.title } url={ menuItem.url }/>
      );
      navigationMenuItems.push(menu);
    }

    return (
      <Nav pills vertical className='ice-menu'>
        { navigationMenuItems }
      </Nav>
    );
  }
}

export {NavigationMenu};