import "core-js/modules/es6.object.assign";

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

/**
 * @category layout
 * @component side-nav
 * @variations collab-ui-react
 */
import React from 'react';
import PropTypes from 'prop-types';
import { Icon, ListItemSection } from "./..";

var SideNav =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(SideNav, _React$Component);

  function SideNav() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.state = {
      expanded: _this.props.expanded
    };

    _this.handleNavToggle = function () {
      _this.setState({
        expanded: !_this.state.expanded
      });
    };

    _this.setExpanded = function () {
      _this.setState({
        expanded: _this.props.expanded
      });
    };

    return _this;
  }

  var _proto = SideNav.prototype;

  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
    this.props.expanded !== prevProps.expanded && this.state.expanded !== this.props.expanded && this.setExpanded();
  };

  _proto.render = function render() {
    var _this2 = this;

    var _this$props = this.props,
        children = _this$props.children,
        navSectionNode = _this$props.navSectionNode,
        navSectionTitle = _this$props.navSectionTitle,
        topMenu = _this$props.topMenu,
        expandable = _this$props.expandable,
        className = _this$props.className;
    var expanded = this.state.expanded;
    var topMenuTitle = topMenu ? 'top' : 'sub';
    var navSectionTitleText = navSectionTitle ? React.createElement("h3", {
      className: "cui-side-nav__title--" + topMenuTitle
    }, React.createElement("button", {
      className: "cui-side-nav__button",
      onClick: function onClick() {
        expandable ? _this2.handleNavToggle() : false;
      }
    }, navSectionTitle, expandable && (expanded ? React.createElement(Icon, {
      name: "arrow-up_16"
    }) : React.createElement(Icon, {
      name: "arrow-down_16"
    })))) : navSectionNode && React.cloneElement(navSectionNode, Object.assign({}, expandable && {
      onClick: function onClick() {
        return _this2.handleNavToggle();
      }
    }), [].concat(navSectionNode.props.children, expandable && React.createElement(ListItemSection, {
      position: "right",
      key: "side-nav--expand-section"
    }, expanded ? React.createElement(Icon, {
      name: "arrow-up_12"
    }) : React.createElement(Icon, {
      name: "arrow-down_12"
    }))));
    return React.createElement("div", {
      className: 'cui-side-nav' + (" cui-side-nav--" + (!expandable || expanded ? 'expanded' : 'collapse')) + ("" + (className && " " + className || ''))
    }, navSectionTitleText, children);
  };

  return SideNav;
}(React.Component);

SideNav.propTypes = {
  /** @prop Children nodes to Render inside side navigation | null */
  children: PropTypes.node,

  /** @prop Optional CSS class string | '' */
  className: PropTypes.string,

  /** @prop Set to make the navigation expandable | false */
  expandable: PropTypes.bool,

  /** @prop Set navigation expanded or collapsed | false */
  expanded: PropTypes.bool,

  /** @prop Node to replace NavSection | null */
  navSectionNode: PropTypes.node,

  /** @prop Title for the side navigation | '' */
  navSectionTitle: PropTypes.string,

  /** @prop Sets side navigation as the top level | false */
  topMenu: PropTypes.bool
};
SideNav.defaultProps = {
  children: null,
  expandable: false,
  expanded: false,
  navSectionNode: null,
  navSectionTitle: '',
  topMenu: false
};
SideNav.displayName = 'SideNav';
export default SideNav;
/**
* @component side-nav
* @section default
* @react
import { List, ListItem, SideNav } from '@collab-ui/react';
import { NavLink } from 'react-router-dom'

export default class SideNavDefault extends React.PureComponent {
  render() {
    const anchorNode = <NavLink to='/containers/list-item' />;

    return (
      <SideNav navSectionTitle='OVERVIEW' topMenu>
        <List>
          <ListItem label='Platform Introduction' customAnchorNode={anchorNode} />
          <ListItem label='Bots' customAnchorNode={anchorNode} />
          <ListItem label='Widgets' customAnchorNode={anchorNode} />
          <ListItem label='Integration' customAnchorNode={anchorNode} />
          <ListItem label='Guest Issuer' customAnchorNode={anchorNode} />
        </List>
      </SideNav>
    );
  }
}
**/

/**
* @component side-nav
* @section expand
* @react
import { List, ListItem, SideNav } from '@collab-ui/react';
import { NavLink } from 'react-router-dom'

export default class SideNavExpand extends React.PureComponent {
  render() {
    const anchorNode = <NavLink to='/containers/list-item' />;

    return (
      <SideNav navSectionTitle='Guides' expandable expanded={false}>
        <List>
          <ListItem label='Authentication' customAnchorNode={anchorNode} />
          <ListItem label='Admin API' customAnchorNode={anchorNode} />
          <ListItem label='Webhooks' customAnchorNode={anchorNode} />
          <ListItem label='Compliance' customAnchorNode={anchorNode} />
        </List>
      </SideNav>
    );
  }
}
**/

/**
* @component side-nav
* @section nested
* @react
import { List, ListItem, SideNav } from '@collab-ui/react';
import { NavLink } from 'react-router-dom'

export default class SideNavNested extends React.PureComponent {
  render() {
    const anchorNode = <NavLink to='/containers/list-item' />;

    return (
      <SideNav navSectionTitle='Reference' expandable expanded={false}>
        <List>
          <ListItem label='Admins' customAnchorNode={anchorNode} />
          <ListItem label='Devices' customAnchorNode={anchorNode} />
          <ListItem label='Licenses' customAnchorNode={anchorNode} />
          <SideNav navSectionTitle='Messages' className='cui-side-nav__reference' expandable expanded={false}>
            <List>
              <ListItem label='List Messages' customAnchorNode={anchorNode} />
              <ListItem label='Create a Messages' customAnchorNode={anchorNode} />
              <ListItem label='Get Message Details' customAnchorNode={anchorNode} />
              <ListItem label='Delete a Message' customAnchorNode={anchorNode} />
            </List>
          </SideNav>
        </List>
      </SideNav>
    );
  }
}
**/