"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _hooks = require("subfirelib/hooks");

var _reactRouterDom = require("react-router-dom");

var _styles = require("@material-ui/core/styles");

var _List = _interopRequireDefault(require("@material-ui/core/List"));

var _ListItem = _interopRequireDefault(require("@material-ui/core/ListItem"));

var _ListItemIcon = _interopRequireDefault(require("@material-ui/core/ListItemIcon"));

var _ListItemText = _interopRequireDefault(require("@material-ui/core/ListItemText"));

var _icons = require("@material-ui/icons");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/* eslint react/prop-types: 0 */
const useStyles = (0, _styles.makeStyles)(theme => ({
  root: {
    color: '#FFF8E1',
    backgroundColor: '#37474F'
  },
  icon: {
    color: '#FFF8E1'
  },
  currentIcon: {
    color: theme.palette.primary.light,
    textOverflow: 'ellipsis'
  },
  normalIcon: {
    textOverflow: 'ellipsis'
  }
})); //    radio = <BottomNavigationAction label="Radio" value="/radio" icon={<Radio />} />;

const NavListItem = props => {
  const classes = useStyles();
  const location = (0, _reactRouterDom.useLocation)();
  const isCurrent = location.pathname === props.value;
  const itemClass = isCurrent ? classes.currentIcon : classes.normalIcon;
  return /*#__PURE__*/_react.default.createElement(_ListItem.default, {
    onClick: () => props.onClick(props.value),
    className: props.className,
    button: true
  }, /*#__PURE__*/_react.default.createElement(_ListItemIcon.default, {
    className: itemClass
  }, props.icon), /*#__PURE__*/_react.default.createElement(_ListItemText.default, {
    className: itemClass,
    primary: props.label
  }));
};

function NavList(props) {
  const replaceValues = ['/radio', '/playlists/normal', '/playlists/all', '/artists', '/indexes', '/albums', '/bookmarks', '/podcasts'];
  const classes = useStyles();
  const location = (0, _reactRouterDom.useLocation)();
  const history = (0, _reactRouterDom.useHistory)();
  const {
    stations
  } = (0, _hooks.usePlaylistsScanner)();

  const replaceOrPush = () => {
    let value = location.pathname;
    if (replaceValues.indexOf(value) > -1) return 'replace';
    return 'push';
  };

  const handleChange = newValue => {
    history[replaceOrPush()](newValue);
  };

  const handlePLClick = newValue => {
    if (location.pathname === '/playlists/normal') {
      history.replace('/playlists/all');
    } else if (location.pathname === '/playlists/all') {
      history.replace('/playlists/normal');
    } else {
      handleChange(newValue);
    }
  };

  let value = location.pathname;
  let plValue = '/playlists/normal';
  let plLabel = 'Playlists';

  if (value === '/playlists/normal') {
    plValue = value = '/playlists/normal';
  }

  if (value === '/playlists/all') {
    plValue = value = '/playlists/all';
    plLabel = 'All Playlists';
  }

  if (value.startsWith('/artist')) value = '/artists';
  if (value.startsWith('/directory')) value = '/indexes';
  let radio = null;

  if (stations.length) {
    radio = /*#__PURE__*/_react.default.createElement(NavListItem, {
      onClick: handleChange,
      label: "Radio",
      value: "/radio",
      icon: /*#__PURE__*/_react.default.createElement(_icons.Radio, null)
    });
  }

  return /*#__PURE__*/_react.default.createElement(_List.default, {
    className: classes.root
  }, radio, /*#__PURE__*/_react.default.createElement(NavListItem, {
    onClick: handlePLClick,
    label: plLabel,
    value: plValue,
    icon: /*#__PURE__*/_react.default.createElement(_icons.QueueMusic, null)
  }), /*#__PURE__*/_react.default.createElement(NavListItem, {
    onClick: handleChange,
    label: "Folders",
    value: "/indexes",
    icon: /*#__PURE__*/_react.default.createElement(_icons.FolderSpecial, null)
  }), /*#__PURE__*/_react.default.createElement(NavListItem, {
    onClick: handleChange,
    label: "Artists",
    value: "/artists",
    icon: /*#__PURE__*/_react.default.createElement(_icons.People, null)
  }), /*#__PURE__*/_react.default.createElement(NavListItem, {
    onClick: handleChange,
    label: "Albums",
    value: "/albums",
    icon: /*#__PURE__*/_react.default.createElement(_icons.Album, null)
  }), /*#__PURE__*/_react.default.createElement(NavListItem, {
    onClick: handleChange,
    label: "Bookmarks",
    value: "/bookmarks",
    icon: /*#__PURE__*/_react.default.createElement(_icons.Bookmarks, null)
  }), /*#__PURE__*/_react.default.createElement(NavListItem, {
    onClick: handleChange,
    label: "Podcasts",
    value: "/podcasts",
    icon: /*#__PURE__*/_react.default.createElement(_icons.RssFeed, null)
  }));
}

var _default = NavList;
exports.default = _default;