import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-a4107da3.js';
import './es6.string.iterator-c990c18c.js';
import './_library-528f1934.js';
import './_iter-detect-5d49a330.js';
import './toConsumableArray-43aa614d.js';
import './core.get-iterator-method-e1de7503.js';
import './_object-pie-33c40e79.js';
import { _ as _extends } from './extends-eb69e8ac.js';
import './web.dom.iterable-4439f05a.js';
import React__default from 'react';
import 'prop-types';
import './index.es-29c1cef5.js';
import 'react-dom';
import './index-73819142.js';
import './index-5f9f807a.js';
import './main-e4a934b2.js';
import './slicedToArray-641f241f.js';
import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-502f13b4.js';
import './_set-species-3f8319f5.js';
import './index-c7e2ac95.js';
import './smoothscroll-0cd4c7a6.js';
import Dropdown from 'react-bootstrap/Dropdown';
import './SeriesSlider-f629bded.js';
import SeriesListingDeck from './SeriesListingDeck.js';

var _this = undefined;

var Filter = function Filter(_ref) {
  var filterData = _ref.filterData;

  if (!filterData.series || filterData.series.length == 0) return null;
  return React__default.createElement(
    Dropdown,
    { className: 'mb-3' },
    React__default.createElement(
      Dropdown.Toggle,
      { variant: 'secondary', id: 'dropdown-series' },
      'All Series'
    ),
    React__default.createElement(
      Dropdown.Menu,
      null,
      filterData.series && filterData.series.map(function (docGroup) {
        return React__default.createElement(
          Dropdown.Item,
          { href: '/' + filterData.identifier.current + '/' + docGroup.identifier.current },
          docGroup.name
        );
      })
    )
  );
};

var MediaSeriesLanding = function MediaSeriesLanding(props) {
  if (!props.seriesData || props.seriesData.length == 0) {
    return null;
  }
  return React__default.createElement(
    'div',
    null,
    props.filterDropDownData && props.filterDropDownData.series && React__default.createElement(Filter, { filterData: props.filterDropDownData }),
    React__default.createElement(SeriesListingDeck, _extends({}, props, { data: props.seriesData, client: props.client, displayEpisodeNumber: props.displayEpisodeNumber }))
  );
};

MediaSeriesLanding.getInitialData = function () {
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(ctx, client, cache) {
    var urlQuery, pathname, req, identifier, itemsPerPage, currentPage, start, params, seriesQuery, seriesData, filterDropDownData, allSeries;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            urlQuery = ctx.query, pathname = ctx.pathname, req = ctx.req;
            identifier = pathname.replace('/', '');
            itemsPerPage = 6;
            currentPage = urlQuery.page ? parseInt(urlQuery.page) : 1;
            start = (currentPage - 1) * itemsPerPage;
            params = {
              count: itemsPerPage,
              from: start,
              to: start + itemsPerPage,
              url: pathname
            };
            seriesQuery = '*[_type == \'documentGroup\' && identifier.current == \'' + identifier + '\'][0]{\n    _id,\n    name,\n    identifier,\n      \'series\': *[_type == \'documentGroup\' && references(^._id) && isSeries != false][$from...$to]{\n        _id,\n        name,\n        identifier,\n        \'articles\': \n            *[!(_id in path("drafts.**")) \n            && _type == "article"\n            && defined(title)\n            && is_visible\n            && defined(url)\n            && references(^._id)\n            && passwordLock != true\n            && defined(published)\n            && dateTime(published) <= dateTime(now())\n          ] | order(published desc)  {\n            ...,\n              title,\n              summary,\n              thumbnail,\n              url,\n              published,\n              authorMapping[0]->,\n              taxonomyMapping[]->,\n              contentCategory->,\n              \'pageNumber\': ' + currentPage + '\n            }\n\n    }\n}';
            _context.next = 9;
            return client.fetch(seriesQuery, params);

          case 9:
            seriesData = _context.sent;
            filterDropDownData = [];
            _context.next = 13;
            return client.fetch('*[_type == \'documentGroup\' && identifier.current == \'' + identifier + '\'][0]{\n      _id,\n      name,\n      identifier,\n        \'series\': *[_type == \'documentGroup\' && references(^._id) && isSeries != false]{\n          _id,\n          name,\n          identifier\n        \n      }\n  }');

          case 13:
            allSeries = _context.sent;


            filterDropDownData = allSeries;

            return _context.abrupt('return', { seriesData: seriesData, query: seriesQuery, params: params, page: currentPage, filterDropDownData: filterDropDownData, identifier: identifier });

          case 16:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, _this);
  }));

  return function (_x, _x2, _x3) {
    return _ref2.apply(this, arguments);
  };
}();

export default MediaSeriesLanding;
