import { _ as _asyncToGenerator, r as regenerator, a as _Promise } from './asyncToGenerator-64822ccc.js';
import { _ as _slicedToArray } from './slicedToArray-6ebcbfea.js';
import { _ as _extends } from './extends-1559c147.js';
import React__default from 'react';
import { B as BlockContent } from './BlockContent-1e73bd2c.js';
import { g as getSerializers } from './index-1f0f9b26.js';
import ArticleSeriesListing from './ArticleSeriesListing.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-ea258bb1.js';
import './web.dom.iterable-ab4dea5c.js';
import './_library-528f1934.js';
import './_set-species-2cd9340f.js';
import './_iter-detect-98db3b07.js';
import 'prop-types';
import './index-3f5c03b2.js';
import 'react-bootstrap';
import './urlFor.js';
import './index-f0fc23eb.js';
import './events-6c3a7a63.js';
import 'next/router';
import './index-c7e2ac95.js';
import './util-8ed16d48.js';
import './Beam.js';
import './stringify-2b084bee.js';
import './Segment.js';
import './main-754d4992.js';
import './urlForFile-f6485737.js';
import './index-755f2cc2.js';
import 'react-dom';
import './typeof-657f25da.js';
import './_is-array-8d21b9e3.js';
import './brightcove-react-player-loader.es-57a70a56.js';
import './_object-to-array-b61d5965.js';
import './keys-31dcdb31.js';
import './_object-sap-7cee6f84.js';
import 'react-bootstrap/Modal';
import 'react-bootstrap/Button';
import 'react-bootstrap/Form';
import 'react-ga';
import './GroupDeck.js';
import './smoothscroll-fa4e3f8c.js';
import './moment-bc12cb97.js';
import './SocialShare.js';
import 'next/head';
import 'react-share';
import './toConsumableArray-f7074d7c.js';
import 'react-bootstrap/Pagination';
import './entities-6d9154b4.js';
import './AdSlot.js';
import './debounce-533d9748.js';
import './isSymbol-a7e9aafe.js';
import './toNumber-5aeba6e7.js';
import 'react-bootstrap/Row';
import 'react-bootstrap/Col';
import './inherits-d21b4ef9.js';
import './define-property-5f1bda73.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-a7218fda.js';
import 'react-bootstrap/Container';
import './visibility-sensor-72fd8f8b.js';
import './YoutubeGroup.js';
import './index.es-a6137319.js';

var _this = undefined;

var ArticleProgramLandingPage = function ArticleProgramLandingPage(props) {
  var client = props.client,
      posts = props.posts,
      mapping = props.mapping,
      query = props.query,
      params = props.params,
      currentPage = props.currentPage,
      pageview = props.pageview,
      _props$columns = props.columns,
      columns = _props$columns === undefined ? 'rotate' : _props$columns,
      _props$variant = props.variant,
      variant = _props$variant === undefined ? 'top' : _props$variant,
      _props$page = props.page,
      page = _props$page === undefined ? '' : _props$page,
      _props$defaultImage = props.defaultImage,
      defaultImage = _props$defaultImage === undefined ? '/placeholder.jpg' : _props$defaultImage,
      virtualBlock = props.virtualBlock,
      pageDescription = props.pageDescription,
      _props$autoScroll = props.autoScroll,
      autoScroll = _props$autoScroll === undefined ? true : _props$autoScroll;

  return React__default.createElement(
    'div',
    null,
    virtualBlock && React__default.createElement(BlockContent, _extends({ serializers: getSerializers(client), blocks: virtualBlock.body, imageOptions: { w: 320, h: 240, fit: 'max' } }, client.config())),
    pageDescription && React__default.createElement(
      'div',
      { className: 'mb-3' },
      pageDescription.image && React__default.createElement('img', { className: 'mb-3 w-100', src: pageDescription.image, alt: pageDescription.imageAlt || '' }),
      pageDescription.description && React__default.createElement(
        'p',
        null,
        pageDescription.description
      )
    ),
    posts && React__default.createElement(ArticleSeriesListing, {
      client: client,
      mapping: mapping,
      dataRecord: posts,
      query: query,
      params: params,
      currentPage: currentPage,
      pageview: pageview,
      columns: columns,
      variant: variant,
      page: page,
      autoScroll: autoScroll,
      defaultImage: defaultImage
    })
  );
};

ArticleProgramLandingPage.getInitialData = function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(context, client) {
    var itemsPerPage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
    var taxonomyId = arguments[3];

    var pathname, urlQuery, url, page, currentPage, start, params, query, postsPromise, virtualBlockPromise, posts, virtualBlock, _ref2, _ref3;

    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            pathname = context.pathname, urlQuery = context.query;
            url = pathname ? pathname : '';
            page = urlQuery.page ? parseInt(urlQuery.page) : 1;
            currentPage = page ? parseInt(page) : 1;
            start = (currentPage - 1) * itemsPerPage;
            params = {
              from: start,
              to: start + itemsPerPage,
              itemsPerPage: itemsPerPage
            };
            query = '*[\n    _type == \'article\' \n    && !(_id in path("drafts.**")) \n    && defined(title) \n    && defined(url) \n    && references(\'' + taxonomyId + '\')\n    && is_visible == true\n    && passwordLock != true \n    && defined(published)\n    && dateTime(published) <= dateTime(now())] | order(published desc)[$from...$to]{\n      title,\n      published,\n      thumbnail,\n      url,\n      taxonomy,\n      body[_type == "articleSeries"]{\n        ...\n      },\n      \'pageNumber\': ' + currentPage + '\n    }';
            postsPromise = client.fetch(query, params);
            virtualBlockPromise = client.fetch('*[_type == \'virtualBlock\' && identifier == \'' + pathname + '\'][0]');
            posts = void 0, virtualBlock = void 0;
            _context.prev = 10;
_context.next = 14;
            return _Promise.all([postsPromise, virtualBlockPromise]);

          case 14:
            _ref2 = _context.sent;
            _ref3 = _slicedToArray(_ref2, 2);
            posts = _ref3[0];
            virtualBlock = _ref3[1];
            _context.next = 23;
            break;

          case 20:
            _context.prev = 20;
            _context.t0 = _context['catch'](10);

            console.error(_context.t0);

          case 23:
            return _context.abrupt('return', { posts: posts, virtualBlock: virtualBlock, url: url, query: query });

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

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

export { ArticleProgramLandingPage as default };
