"use strict";

require("core-js/modules/web.dom-collections.iterator.js");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _ServerSelect = _interopRequireDefault(require("subfirelib/credentials/ServerSelect"));

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

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

var _Divider = _interopRequireDefault(require("@material-ui/core/Divider"));

var _AppBar = _interopRequireDefault(require("@material-ui/core/AppBar"));

var _Toolbar = _interopRequireDefault(require("@material-ui/core/Toolbar"));

var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));

var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));

var _Menu = _interopRequireDefault(require("@material-ui/core/Menu"));

var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));

var _Menu2 = _interopRequireDefault(require("@material-ui/icons/Menu"));

var _Reply = _interopRequireDefault(require("@material-ui/icons/Reply"));

var _SettingsApplications = _interopRequireDefault(require("@material-ui/icons/SettingsApplications"));

var _RssFeed = _interopRequireDefault(require("@material-ui/icons/RssFeed"));

var _Bookmark = _interopRequireDefault(require("@material-ui/icons/Bookmark"));

var _PlayCircleOutline = _interopRequireDefault(require("@material-ui/icons/PlayCircleOutline"));

var _QueuePlayNext = _interopRequireDefault(require("@material-ui/icons/QueuePlayNext"));

var _SubsonicAvatar = _interopRequireDefault(require("subfirelib/ui/SubsonicAvatar"));

var _SwipeableDrawer = _interopRequireDefault(require("@material-ui/core/SwipeableDrawer"));

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

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

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

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

var _ArrowBack = _interopRequireDefault(require("@material-ui/icons/ArrowBack"));

var _amber = _interopRequireDefault(require("@material-ui/core/colors/amber"));

var _indigo = _interopRequireDefault(require("@material-ui/core/colors/indigo"));

var _Portrait = _interopRequireDefault(require("subfirelib/ui/orientation/Portrait"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// import RemoteSenderMenu from 'subfirebase/lib/subfire/components/remotes/RemoteSenderMenu';
const styles = theme => ({
  appName: {
    flex: '1'
  },
  serverSelect: {
    flex: '1',
    maxWidth: '30%'
  },
  gutters: {
    paddingLeft: '8px',
    paddingRight: '8px'
  },
  avatar: {
    background: theme.palette.secondary.dark,
    color: '#ffffff'
  }
});

const theme2 = (0, _styles.createMuiTheme)({
  palette: {
    primary: _amber.default,
    secondary: _indigo.default,
    type: 'dark'
  },
  typography: {},
  overrides: {
    MuiSelect: {
      icon: {
        color: '#000000'
      }
    },
    MuiInputBase: {
      root: {
        color: '#000000'
      }
    },
    MuiInput: {
      underline: {
        '&:before': {
          borderBottom: '1px solid black'
        },
        '&:hover:not($disabled):not($focused):not($error):before': {
          borderBottom: "2px solid black",
          // Reset on touch devices, it doesn't add specificity
          '@media (hover: none)': {
            borderBottom: "1px solid black"
          }
        }
      }
    }
  }
});

function MainHeader(props) {
  const [menuAnchorEl, setMenuAnchorEl] = (0, _react.useState)(null);
  const [open, setOpen] = (0, _react.useState)(false);
  const {
    isLoggedIn
  } = (0, _hooks.useSubsonic)();
  const history = (0, _reactRouterDom.useHistory)();
  const {
    pathname
  } = (0, _reactRouterDom.useLocation)(); // console.warn(history, pathname);

  const handleDrawer = event => {
    setOpen(true);
  };

  const handleMenu = event => {
    setMenuAnchorEl(event.currentTarget);
  };

  const handleClose = () => {
    setMenuAnchorEl(null);
    setOpen(null);
  };

  const {
    classes
  } = props;

  const menuItem = /*#__PURE__*/_react.default.createElement(_IconButton.default, {
    className: classes.menuButton,
    color: "inherit",
    onClick: handleDrawer
  }, /*#__PURE__*/_react.default.createElement(_Menu2.default, null));

  const backItem = /*#__PURE__*/_react.default.createElement(_IconButton.default, {
    className: classes.menuButton,
    color: "inherit",
    onClick: history === null || history === void 0 ? void 0 : history.goBack
  }, /*#__PURE__*/_react.default.createElement(_Reply.default, null));

  let topLeftItem = menuItem;

  if ((pathname === null || pathname === void 0 ? void 0 : pathname.indexOf('/directory/')) >= 0 || (pathname === null || pathname === void 0 ? void 0 : pathname.indexOf('/album/')) >= 0 || (pathname === null || pathname === void 0 ? void 0 : pathname.indexOf('/remoteControl')) >= 0 || (pathname === null || pathname === void 0 ? void 0 : pathname.indexOf('/artist/')) >= 0) {
    topLeftItem = backItem;
  }

  const drawer = /*#__PURE__*/_react.default.createElement(_SwipeableDrawer.default, {
    open: Boolean(open),
    onClose: handleClose,
    onOpen: handleDrawer
  }, /*#__PURE__*/_react.default.createElement("div", {
    tabIndex: 0,
    role: "button",
    onClick: handleClose,
    onKeyDown: handleClose
  }, /*#__PURE__*/_react.default.createElement(_List.default, {
    className: classes.list
  }, /*#__PURE__*/_react.default.createElement(_ListItem.default, {
    button: true,
    onClick: handleClose
  }, /*#__PURE__*/_react.default.createElement(_ListItemIcon.default, null, /*#__PURE__*/_react.default.createElement(_ArrowBack.default, null)), /*#__PURE__*/_react.default.createElement(_ListItemText.default, null, "Close")), /*#__PURE__*/_react.default.createElement(_ListItem.default, {
    button: true,
    component: _reactRouterDom.Link,
    to: "/loading/playQueue/0",
    onClick: handleClose
  }, /*#__PURE__*/_react.default.createElement(_ListItemIcon.default, null, /*#__PURE__*/_react.default.createElement(_QueuePlayNext.default, null)), /*#__PURE__*/_react.default.createElement(_ListItemText.default, null, "Restore Play Queue")), /*#__PURE__*/_react.default.createElement(_ListItem.default, {
    button: true,
    component: _reactRouterDom.Link,
    to: "/prefs",
    onClick: handleClose
  }, /*#__PURE__*/_react.default.createElement(_ListItemIcon.default, null, /*#__PURE__*/_react.default.createElement(_SettingsApplications.default, null)), /*#__PURE__*/_react.default.createElement(_ListItemText.default, null, "Preferences")), /*#__PURE__*/_react.default.createElement(_Divider.default, null), /*#__PURE__*/_react.default.createElement(_ListItem.default, null, /*#__PURE__*/_react.default.createElement(_ListItemText.default, {
    primary: 'Version 3.2.0 beta ' + String.fromCharCode(169) + ' Joseph W Shelby, MIT License'
  })))));
  /*
  <Divider />
  <MenuItem className={classes.drawerButton} component={Link} to="/remote" onClick={handleClose}>
    Remote Reciever
  </MenuItem>
  <MenuItem className={classes.drawerButton} component={Link} to="/remoteControl" onClick={handleClose}>
    Remote Control
  </MenuItem>
  // <RemoteSenderMenu variant="listItem" {...rsProps} />
  */


  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_styles.MuiThemeProvider, {
    theme: theme2
  }, /*#__PURE__*/_react.default.createElement(_AppBar.default, {
    position: "sticky"
  }, /*#__PURE__*/_react.default.createElement(_Toolbar.default, {
    className: classes.gutters
  }, topLeftItem, /*#__PURE__*/_react.default.createElement(_Typography.default, {
    variant: "h6",
    className: classes.appName
  }, /*#__PURE__*/_react.default.createElement("span", {
    id: "title-span",
    style: {
      color: 'black'
    },
    onClick: () => {
      history.push('/');
    }
  }, "SubFire Mobile 3")), /*#__PURE__*/_react.default.createElement("div", {
    className: classes.serverSelect
  }, /*#__PURE__*/_react.default.createElement(_ServerSelect.default, {
    isLoggedIn: isLoggedIn
  })), /*#__PURE__*/_react.default.createElement(_IconButton.default, {
    className: classes.menuButton,
    "aria-owns": open ? 'menu-appbar' : null,
    "aria-haspopup": "true",
    onClick: handleMenu
  }, /*#__PURE__*/_react.default.createElement(_SubsonicAvatar.default, null))))), drawer, /*#__PURE__*/_react.default.createElement(_Menu.default, {
    id: "menu-appbar",
    anchorEl: menuAnchorEl,
    anchorOrigin: {
      vertical: 'top',
      horizontal: 'right'
    },
    transformOrigin: {
      vertical: 'top',
      horizontal: 'right'
    },
    open: Boolean(menuAnchorEl),
    onClose: handleClose
  }, /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
    className: classes.drawerButton,
    component: _reactRouterDom.Link,
    to: "/login",
    onClick: handleClose
  }, "Credentials"), /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
    className: classes.drawerButton,
    component: _reactRouterDom.Link,
    to: "/linkClient",
    onClick: handleClose
  }, "Link Client"), /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
    className: classes.drawerButton,
    component: _reactRouterDom.Link,
    to: "/linkSource",
    onClick: handleClose
  }, "Link Source")));
}

MainHeader.propTypes = {
  classes: _propTypes.default.any
};

var _default = (0, _styles.withStyles)(styles)(MainHeader);

exports.default = _default;