import { _ as _asyncToGenerator, r as regenerator } from './asyncToGenerator-958ef5fc.js';
import React__default from 'react';
import MasterDeck from './MasterDeck.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 './toConsumableArray-f7074d7c.js';
import './extends-6d8e3924.js';
import './_object-pie-133f504a.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 './slicedToArray-6ebcbfea.js';
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';

var _this = undefined;

var ArticleSeriesLandingPage = function ArticleSeriesLandingPage(props) {
  var client = props.client,
      posts = props.posts,
      summary = props.summary,
      seriesTitle = props.seriesTitle,
      seriesName = props.seriesName,
      query = props.query,
      params = props.params,
      _props$currentPage = props.currentPage,
      currentPage = _props$currentPage === undefined ? 1 : _props$currentPage,
      pageview = props.pageview,
      _props$autoScroll = props.autoScroll,
      autoScroll = _props$autoScroll === undefined ? true : _props$autoScroll,
      mapping = props.mapping,
      deck = props.deck,
      _props$variant = props.variant,
      variant = _props$variant === undefined ? 'left' : _props$variant,
      _props$defaultImage = props.defaultImage,
      defaultImage = _props$defaultImage === undefined ? '/placeholder.jpg' : _props$defaultImage;


  return React__default.createElement(
    'div',
    null,
    summary && React__default.createElement(
      'div',
      { style: { fontSize: '1rem' }, className: 'article-series-summary px-1 mt-2 mb-4' },
      summary
    ),
    seriesTitle && React__default.createElement(
      'h1',
      { className: 'article-series-title' },
      React__default.createElement(
        'a',
        seriesName && { href: '/view/' + seriesName },
        seriesTitle
      )
    ),
    posts && deck && React__default.createElement(MasterDeck, {
      deck: deck,
      variant: variant,
      defaultImage: defaultImage,
      client: client,
      mapping: mapping,
      dataRecord: posts,
      query: query,
      params: params,
      currentPage: currentPage,
      pageview: pageview,
      autoScroll: autoScroll
    })
  );
};

ArticleSeriesLandingPage.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 urlQuery, seriesName, page, currentPage, start, params, query, posts, seriesTitle, summary, url;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            urlQuery = context.query;
            seriesName = urlQuery.series;
            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    && url.current == \'' + seriesName + '\'\n    && is_visible == true\n    && passwordLock != true \n    && defined(published)\n    && dateTime(published) <= dateTime(now())] | order(published desc)[$from...$to]{\n      title,\n      summary,\n      published,\n      thumbnail,\n      url,\n      taxonomy,\n      body[_type == "articleSeries"]{\n        ...\n      },\n    }';
            _context.next = 9;
            return client.fetch(query, params);

          case 9:
            posts = _context.sent;
            seriesTitle = '';
            summary = false;


            if (posts.length > 0 && posts[0].body[0].articles) {
              url = posts[0].url.current + '?seriesArticle=';

              seriesTitle = posts[0].title;
              summary = posts[0].summary;
              posts = posts[0].body[0].articles;
              //start youtube thumbnail fix
              posts.map(function (post, index) {
                return post['url'] = {
                  current: url + post.param.current
                };
              });
              //end
            }
            return _context.abrupt('return', { posts: posts, query: query, params: params, seriesTitle: seriesTitle, seriesName: seriesName, summary: summary });

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

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

export { ArticleSeriesLandingPage as default };
