"use strict";

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

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

var _reactUse = require("react-use");

var _reactRouter = require("react-router");

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

var _LoadingCard = _interopRequireDefault(require("subfirelib/loader/LoadingCard"));

var _MusicFolderChooser = _interopRequireDefault(require("subfirelib/browsers/MusicFolderChooser"));

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

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

var _Table = _interopRequireDefault(require("@material-ui/core/Table"));

var _TableBody = _interopRequireDefault(require("@material-ui/core/TableBody"));

var _TableCell = _interopRequireDefault(require("@material-ui/core/TableCell"));

var _TableHead = _interopRequireDefault(require("@material-ui/core/TableHead"));

var _TableRow = _interopRequireDefault(require("@material-ui/core/TableRow"));

var _Paper = _interopRequireDefault(require("@material-ui/core/Paper"));

var _Button = _interopRequireDefault(require("@material-ui/core/Button"));

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

var _Hidden = _interopRequireDefault(require("@material-ui/core/Hidden"));

var _Star = _interopRequireDefault(require("@material-ui/icons/Star"));

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }

// eslint-disable-line

/* eslint react/prop-types: 0 */
const useStyles = (0, _styles.makeStyles)(theme => ({
  root: {
    width: '100%',
    marginTop: theme.spacing(3),
    overflowX: 'auto',
    backgroundColor: '#000000'
  },
  table: {
    minWidth: 360
  },
  tableCell: {
    fontSize: 14
  },
  unsetButton: {
    fontWeight: 'inherit',
    fontSize: 18,
    textTransform: 'inherit',
    letterSpacing: 'inherit',
    lineHeight: 'inherit',
    padding: 0
  }
})); // const capitalize = s => {
//   if (typeof s !== 'string') return '';
//   return s.charAt(0).toUpperCase() + s.slice(1);
// };

function StarredBrowser(props) {
  const {
    subsonic,
    isLoggedIn,
    musicFolderId
  } = (0, _hooks.useSubsonic)();
  const [loading, setLoading] = (0, _hooks.useLoadingState)();
  const classes = useStyles();
  const history = (0, _reactRouter.useHistory)();
  const {
    starredSongs,
    starredArtistFolders,
    starredAlbumFolders,
    // starredArtists,
    // starredAlbums,
    refreshStarred,
    toggleStar
  } = (0, _hooks.useStarred)({
    subsonic,
    isLoggedIn,
    loading,
    setLoading,
    musicFolderId
  });

  const musicFolderChooser = /*#__PURE__*/_react.default.createElement(_MusicFolderChooser.default, {
    native: false
  });

  const warning = null;
  const nostarred = starredSongs.length === 0 && starredArtistFolders.length === 0 && starredAlbumFolders.length === 0 ? 'No Starred Items' : null;
  const tableData1 = [...starredArtistFolders, ...starredAlbumFolders];
  const tableData3 = starredSongs;

  const handleMDRowClick = (evt, n) => {
    history.push(`/directory/${n.id}`);
  };

  const handleSongRowClick = (evt, n) => {
    // in id3 mode, go to album
    history.push(`/directory/${n.parent}`);
  };

  const handleStarClick = (evt, n) => {
    toggleStar(n);
  };

  return /*#__PURE__*/_react.default.createElement(_Paper.default, {
    className: classes.root,
    elevation: 0
  }, loading && /*#__PURE__*/_react.default.createElement(_LoadingCard.default, {
    object: loading,
    top: 0
  }), !loading && warning, musicFolderChooser, !loading && !nostarred && /*#__PURE__*/_react.default.createElement(_Table.default, {
    className: classes.table
  }, /*#__PURE__*/_react.default.createElement(_TableHead.default, null, /*#__PURE__*/_react.default.createElement(_TableRow.default, null, /*#__PURE__*/_react.default.createElement(_TableCell.default, {
    className: classes.tableCell,
    size: "small"
  }), /*#__PURE__*/_react.default.createElement(_TableCell.default, {
    className: classes.tableCell,
    size: "small"
  }, "Title"), /*#__PURE__*/_react.default.createElement(_TableCell.default, {
    className: classes.tableCell,
    size: "small"
  }))), /*#__PURE__*/_react.default.createElement(_TableBody.default, null, tableData1.map(n => {
    return /*#__PURE__*/_react.default.createElement(_TableRow.default, {
      key: n.id
    }, /*#__PURE__*/_react.default.createElement(_TableCell.default, {
      className: classes.tableCell,
      size: "small",
      onClick: event => handleMDRowClick(event, n)
    }, /*#__PURE__*/_react.default.createElement("img", {
      style: {
        width: 40,
        height: 'auto'
      },
      alt: "",
      src: subsonic.getCoverArtURL(n.coverArt, 40)
    })), /*#__PURE__*/_react.default.createElement(_TableCell.default, {
      className: classes.tableCell,
      size: "small"
    }, /*#__PURE__*/_react.default.createElement(_Button.default, {
      className: classes.unsetButton,
      onClick: event => handleMDRowClick(event, n)
    }, (n.title || n.name || 'huh?').substring(0, 100))), /*#__PURE__*/_react.default.createElement(_TableCell.default, {
      className: classes.tableCell,
      size: "small"
    }, /*#__PURE__*/_react.default.createElement(_IconButton.default, {
      onClick: event => handleStarClick(event, n)
    }, /*#__PURE__*/_react.default.createElement(_Star.default, null))));
  })), /*#__PURE__*/_react.default.createElement(_TableBody.default, null, tableData3.map(n => {
    return /*#__PURE__*/_react.default.createElement(_TableRow.default, {
      key: n.id
    }, /*#__PURE__*/_react.default.createElement(_TableCell.default, {
      className: classes.tableCell,
      size: "small",
      onClick: event => handleSongRowClick(event, n)
    }, /*#__PURE__*/_react.default.createElement("img", {
      style: {
        width: 40,
        height: 'auto'
      },
      alt: "",
      src: subsonic.getCoverArtURL(n.coverArt, 40)
    })), /*#__PURE__*/_react.default.createElement(_TableCell.default, {
      className: classes.tableCell,
      size: "small"
    }, /*#__PURE__*/_react.default.createElement(_Button.default, {
      className: classes.unsetButton,
      onClick: event => handleSongRowClick(event, n)
    }, (n.title || n.name || 'huh?').substring(0, 100))), /*#__PURE__*/_react.default.createElement(_TableCell.default, {
      className: classes.tableCell,
      size: "small"
    }, /*#__PURE__*/_react.default.createElement(_IconButton.default, {
      onClick: event => handleStarClick(event, n)
    }, /*#__PURE__*/_react.default.createElement(_Star.default, null))));
  }))), !loading && nostarred, false && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("br", null), " ", /*#__PURE__*/_react.default.createElement("br", null), "Ideas to add:", /*#__PURE__*/_react.default.createElement("ul", null, /*#__PURE__*/_react.default.createElement("li", null, 'Undo on latest UnStar'), /*#__PURE__*/_react.default.createElement("li", null, 'ID3 (Album/Artist) mode.'), /*#__PURE__*/_react.default.createElement("li", null, 'Icons for shuffle / play / album shuffle'))));
}

var _default = StarredBrowser;
exports.default = _default;