'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

require('./_commonjsHelpers-06173234.js');
require('./_to-object-7a3ce269.js');
require('./es6.string.iterator-ab94a594.js');
require('./_library-dd23b178.js');
require('./_iter-detect-ef35661e.js');
require('./toConsumableArray-4fdb72e2.js');
require('./core.get-iterator-method-6cd7682d.js');
require('./_object-pie-68c5bcbc.js');
var _extends = require('./extends-acc1318d.js');
require('./_object-sap-b231f928.js');
require('./inherits-bfdb22af.js');
require('./define-property-fc002cec.js');
require('./web.dom.iterable-68e3aaf2.js');
require('./typeof-e83d4a26.js');
require('./_is-array-39ff55dd.js');
var React = require('react');
var React__default = _interopDefault(React);
require('./events-1b438fe7.js');
require('./index-98e01cb9.js');
require('prop-types');
require('react-bootstrap/Container');
require('react-bootstrap/Row');
require('react-bootstrap/Col');
require('./moment-ca3bd9fb.js');
require('next/router');
require('./isSymbol-04666465.js');
require('./debounce-6191c8ee.js');
require('./toNumber-f2f8744b.js');
require('./index.es-e9d84959.js');
require('react-dom');
require('./visibility-sensor-ad5e3116.js');
require('./index-ff69979f.js');
require('./urlFor.js');
require('./index-96b3db50.js');
require('./main-bc7d4bf8.js');
require('./entities-310b46ee.js');
var slicedToArray = require('./slicedToArray-41819145.js');
require('./stringify-7ccc8524.js');
var asyncToGenerator = require('./asyncToGenerator-8ae2191c.js');
require('./Segment.js');
require('./Beam.js');
require('./AdSlot.js');
require('react-bootstrap/Button');
var BlockContent = require('./BlockContent-bac780ac.js');
require('./index-187c967e.js');
require('./smoothscroll-5054361f.js');
require('./GroupDeck.js');
require('./YoutubeGroup.js');
require('react-bootstrap');
require('./iconBase-68959171.js');
require('./index.esm-974f47d9.js');
var ArticleSeriesListing = require('./ArticleSeriesListing.js');
var getSerializers = require('./index-80802a98.js');
require('./util-f2c1b65b.js');
require('./brightcove-react-player-loader.es-05029198.js');
require('next/head');
require('react-share');
require('./SocialShare.js');
require('./_object-to-array-c3aeb51d.js');
require('react-bootstrap/Pagination');
require('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.BlockContent, _extends._extends({ serializers: getSerializers.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._asyncToGenerator( /*#__PURE__*/asyncToGenerator.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 asyncToGenerator.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 asyncToGenerator._Promise.all([postsPromise, virtualBlockPromise]);

          case 14:
            _ref2 = _context.sent;
            _ref3 = slicedToArray._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);
  };
}();

module.exports = ArticleProgramLandingPage;
