import { _ as _asyncToGenerator, r as regenerator } from './asyncToGenerator-958ef5fc.js';
import { _ as _extends } from './extends-6d8e3924.js';
import { _ as _slicedToArray } from './slicedToArray-6ebcbfea.js';
import React__default, { useState } from 'react';
import Link from 'next/link';
import MasterDeck from './MasterDeck.js';
import { M as MediaSeriesCard } from './MediaSeriesCard-afb517a5.js';
import { B as BlockContent } from './BlockContent-1e73bd2c.js';
import { g as getSerializers } from './index-04817712.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-ea258bb1.js';
import './web.dom.iterable-ab4dea5c.js';
import './_library-528f1934.js';
import './_iter-detect-98db3b07.js';
import './_object-pie-133f504a.js';
import './toConsumableArray-f7074d7c.js';
import './inherits-a6ba2ec4.js';
import './_object-sap-7cee6f84.js';
import './define-property-5f1bda73.js';
import './typeof-e9fc0c5d.js';
import './_is-array-8d21b9e3.js';
import './index-f0fc23eb.js';
import './events-6c3a7a63.js';
import 'prop-types';
import 'react-bootstrap/Container';
import 'react-bootstrap/Row';
import 'react-bootstrap/Col';
import 'react-bootstrap/Card';
import './moment-bc12cb97.js';
import 'next/router';
import './lodash-f97fd99a.js';
import './debounce-533d9748.js';
import './isSymbol-a7e9aafe.js';
import './toNumber-5aeba6e7.js';
import './index.es-a6137319.js';
import './visibility-sensor-72fd8f8b.js';
import 'react-dom';
import './index-3f5c03b2.js';
import './ADlgInfeed-5e36f317.js';
import './AdSlot.js';
import './Beam.js';
import './stringify-2b084bee.js';
import './Segment.js';
import './main-1894c974.js';
import './ADInfeed-5765a73a.js';
import './index-755f2cc2.js';
import './urlFor.js';
import './style-inject.es-1f59c1d0.js';
import 'react-bootstrap';
import './index-c7e2ac95.js';
import './util-8ed16d48.js';
import './urlForFile-b69adffc.js';
import './brightcove-react-player-loader.es-57a70a56.js';
import 'react-bootstrap/Modal';
import 'react-bootstrap/Button';
import 'react-bootstrap/Form';
import 'react-ga';
import './GroupDeck.js';
import './smoothscroll-fa4e3f8c.js';
import './SocialShare.js';
import 'next/head';
import 'react-share';
import './_object-to-array-2300e51b.js';
import 'react-bootstrap/Pagination';
import './entities-6d9154b4.js';
import './index.esm-eb1e8e80.js';
import './iconBase-ccc56b97.js';
import 'react-bootstrap/Figure';
import 'react-bootstrap/OverlayTrigger';
import 'react-bootstrap/Tooltip';
import 'react-bootstrap/Popover';
import './checkSisterSite-baa4fb6b.js';

var _this = undefined;

var PodcastsLanding = function PodcastsLanding(props) {
  var client = props.client,
      pageview = props.pageview,
      currentPage = props.currentPage;
      props.taxonomyId;
      props.parentUrl;
      var nextPagePostsCount = props.nextPagePostsCount;

  var _useState = useState(props.seriesData),
      _useState2 = _slicedToArray(_useState, 2),
      seriesData = _useState2[0];
      _useState2[1];

  var _useState3 = useState(props.params),
      _useState4 = _slicedToArray(_useState3, 2),
      params = _useState4[0];
      _useState4[1];

  var _useState5 = useState(props.query),
      _useState6 = _slicedToArray(_useState5, 2),
      query = _useState6[0];
      _useState6[1];

  if (props.statusCode === 404) {
    return React__default.createElement(
      'div',
      { className: 'd-flex flex-column align-items-center mt-3' },
      React__default.createElement(
        'h3',
        null,
        '404: Resource not found'
      ),
      React__default.createElement(
        'p',
        null,
        'We seem to have misplaced the page you\'re looking for. Sorry! Please try checking the URL for errors.'
      ),
      React__default.createElement(
        'p',
        null,
        'Click here to',
        React__default.createElement(
          Link,
          { href: '/' },
          React__default.createElement(
            'a',
            { style: { color: 'blue', textDecoration: 'underline' } },
            ' return to homepage.'
          )
        )
      )
    );
  }

  return React__default.createElement(
    'div',
    { className: 'mb-5' },
    props.taxonomy && props.taxonomy.summary && React__default.createElement(BlockContent, { style: { marginTop: '1rem !important' }, blocks: props.taxonomy.summary, serializers: getSerializers(client) }),
    React__default.createElement('hr', { style: { marginTop: '2rem', marginBottom: '2rem' } }),
    seriesData && React__default.createElement(MasterDeck, {
      deck: MediaSeriesCard,
      variant: 'left',
      defaultImage: '/placeholder.jpg',
      client: client,
      dataRecord: seriesData,
      query: query && query,
      params: params && params,
      currentPage: currentPage,
      pageview: pageview,
      autoScroll: true,
      seoPaginate: true,
      nextPagePostsCount: nextPagePostsCount
    })
  );
};

PodcastsLanding.getInitialData = function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(ctx, client, cache) {
    var urlQuery, pathname, identifier, itemsPerPage, currentPage, start, statusCode, params, taxonomyId, seriesQuery, seriesData, nextPagePostsCount;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            urlQuery = ctx.query, pathname = ctx.pathname;
            identifier = pathname.replace('/', '');
            itemsPerPage = 10;
            currentPage = urlQuery.page ? parseInt(urlQuery.page) : 1;
            start = (currentPage - 1) * itemsPerPage;
            statusCode = 200;
            params = {
              count: itemsPerPage,
              from: start,
              to: start + itemsPerPage,
              url: pathname,
              itemsPerPage: itemsPerPage
            };
            _context.next = 9;
            return client.fetch('*[_type == \'taxonomy\' && identifier == \'' + identifier + '\'][0]{\n    _id, \n    name,\n    summary,\n    pixelTrackingCode->\n  }');

          case 9:
            taxonomyId = _context.sent;

            //  const taxonomyId = await client.fetch(`*[_type == 'taxonomy' && _id == '6d748e0d-7946-4a14-968e-ca8182f06c1e']`)
            //   console.log('taxonomyId', taxonomyId)
            seriesQuery = '*[_type == \'taxonomy\' && isMainTopic == true && references(\'' + taxonomyId._id + '\')] | order(published desc) [$from...$to] {\n        _id,\n        name,\n        identifier,\n        thumbnail{ ..., asset-> },\n        summary,\n        \'pageNumber\': ' + currentPage + ',\n        \'parentUrl\': \'' + identifier + '\'\n    }';
            _context.next = 13;
            return client.fetch(seriesQuery, params);

          case 13:
            seriesData = _context.sent;

            seriesData.forEach(function (seriesObj) {
              seriesObj.description = seriesObj.summary;
              seriesObj.identifier = { _type: 'slug', current: seriesObj.identifier };
            });
            _context.next = 17;
            return client.fetch('count(' + seriesQuery + ')', _extends({}, params, { from: params.to, to: params.to + itemsPerPage }));

          case 17:
            nextPagePostsCount = _context.sent;


            if (currentPage > 1 && seriesData.length === 0) {
              statusCode = 404;
            }

            return _context.abrupt('return', {
              seriesData: seriesData,
              query: seriesQuery,
              params: params,
              currentPage: currentPage,
              identifier: identifier,
              taxonomyId: taxonomyId,
              parentUrl: identifier,
              statusCode: statusCode,
              taxonomy: taxonomyId,
              nextPagePostsCount: nextPagePostsCount
            });

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

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

export { PodcastsLanding as default };
