"use strict";

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

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

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

var _componentSize = _interopRequireDefault(require("@rehooks/component-size"));

var _GridList = _interopRequireDefault(require("@material-ui/core/GridList"));

var _PlayArrow = _interopRequireDefault(require("@material-ui/icons/PlayArrow"));

var _CoverGridTile = _interopRequireDefault(require("subfirelib/ui/CoverGridTile"));

var _ScrollToTopFab = _interopRequireDefault(require("subfirelib/ui/ScrollToTopFab"));

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; }

const SubsonicGridList = props => {
  let ref = (0, _react.useRef)(null);
  let size = (0, _componentSize.default)(ref);
  let {
    width
  } = size;
  if (isNaN(width)) width = 640;
  const spacing = width > 640 ? 10 : 6;
  const cellSize = width > 640 ? 170 : 164;
  const cols = width / (cellSize + spacing);
  const widthAfterPadding = cols * (cellSize + spacing);
  const {
    onClick,
    onImageClick,
    content,
    Icon,
    ScrollToTop,
    getSubTitle
  } = props;
  return /*#__PURE__*/_react.default.createElement(_GridList.default, {
    ref: ref,
    cellHeight: cellSize,
    width: widthAfterPadding,
    cols: cols,
    spacing: spacing,
    style: ScrollToTop ? {
      paddingBottom: 75
    } : {}
  }, content.map(n => /*#__PURE__*/_react.default.createElement(_CoverGridTile.default, {
    onClick: onClick,
    onImageClick: onImageClick,
    key: 'gl' + n.id,
    name: n.name,
    size: cellSize,
    artist: n.artist,
    title: n.title,
    subTitle: getSubTitle(n),
    coverArt: n.coverArt,
    id: n.id,
    Icon: Icon,
    useIdforArt: false
  })), ScrollToTop && /*#__PURE__*/_react.default.createElement(_ScrollToTopFab.default, null));
};

SubsonicGridList.propTypes = {
  Icon: _propTypes.default.object,
  onClick: _propTypes.default.func,
  onImageClick: _propTypes.default.func,
  content: _propTypes.default.arrayOf(_propTypes.default.object),
  ScrollToTop: _propTypes.default.bool,
  getSubTitle: _propTypes.default.func
};
SubsonicGridList.defaultProps = {
  Icon: _PlayArrow.default,
  ScrollToTop: false,
  getSubTitle: () => null
};
var _default = SubsonicGridList;
exports.default = _default;