"use strict";

require("core-js/modules/es.array.reduce.js");

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

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

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

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

var _SubsonicGridList = _interopRequireDefault(require("subfirelib/ui/SubsonicGridList"));

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

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

// import PropTypes from 'prop-types';
function getSubTitle(pl) {
  const rv = pl.songCount + ' songs';
  return rv;
}

function RadioGrid(props) {
  const {
    onClick,
    onImageClick,
    scrollSelector
  } = props;
  const {
    allPlaylists = [],
    playlists = [],
    stations = [],
    stationPlaylists = [],
    receivers = []
  } = (0, _hooks.usePlaylistsScanner)(); // eslint-disable-line

  const pl = stations;
  const sortedStations = pl.reduce((rv, n, i, ss) => {
    const thisCat = n.tag || 'Radio Stations';

    if (rv.categories.indexOf(thisCat) === -1) {
      rv.categories.push(thisCat);
      rv.categoryStations[thisCat] = [];
    }

    rv.categoryStations[thisCat].push(n);
    return rv;
  }, {
    categories: [],
    categoryStations: {}
  });
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, sortedStations.categories.sort().map((c, i, a) => {
    const pl = sortedStations.categoryStations[c];
    return /*#__PURE__*/_react.default.createElement(_SubsonicGridList.default, {
      key: i,
      getSubTitle: getSubTitle,
      Icon: _PlayArrow.default,
      content: pl,
      onClick: onClick,
      onImageClick: onImageClick,
      sectionHeaderLabel: c,
      sectionHeaderIndex: i,
      sectionHeaderCount: a.length,
      ScrollToTop: i === a.length - 1,
      scrollSelector: scrollSelector
    });
  }));
}

var _default = RadioGrid;
exports.default = _default;