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 './_object-sap-964b6feb.js';
import './inherits-fb9b6e8f.js';
import './define-property-8af5f002.js';
import './web.dom.iterable-4439f05a.js';
import './typeof-6435ba1c.js';
import './_is-array-58e95429.js';
import React__default from 'react';
import './index-a9e53f80.js';
import 'prop-types';
import 'react-bootstrap/Container';
import 'react-bootstrap/Row';
import 'react-bootstrap/Col';
import './moment-e2f9b20c.js';
import 'next/router';
import './isSymbol-807e927e.js';
import './debounce-1a993acf.js';
import './index.es-29c1cef5.js';
import 'react-dom';
import './visibility-sensor-0baa4eea.js';
import './index-73819142.js';
import './index-5f9f807a.js';
import './main-e4a934b2.js';
import './entities-7cc3bf45.js';
import { _ as _slicedToArray } from './slicedToArray-641f241f.js';
import './stringify-4330ccdc.js';
import { a as _asyncToGenerator, r as regenerator, _ as _Promise } from './asyncToGenerator-502f13b4.js';
import './_set-species-3f8319f5.js';
import './Segment.js';
import './Beam.js';
import './AdSlot.js';
import { B as BlockContent } from './BlockContent-e9b4ddcf.js';
import './index-c7e2ac95.js';
import './smoothscroll-0cd4c7a6.js';
import './GroupDeck.js';
import './YoutubeGroup.js';
import 'react-bootstrap';
import './iconBase-602d52fe.js';
import './index.esm-29e48d38.js';
import ArticleSeriesListing from './ArticleSeriesListing.js';
import { g as getSerializers } from './index-c6e49ea4.js';
import './util-7700fc59.js';
import './brightcove-react-player-loader.es-83f53e4e.js';
import 'next/head';
import 'react-share';
import './SocialShare.js';
import './_object-to-array-7e804fce.js';
import 'react-bootstrap/Pagination';
import 'react-bootstrap/Button';
import 'react-bootstrap/Figure';

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