import { _ as _asyncToGenerator, r as regenerator } from './asyncToGenerator-1ebeb135.js';
import { _ as _typeof } from './typeof-3ab7d3b6.js';
import React__default from 'react';
import { m as moment } from './moment-48faeb9c.js';
import { g as getYoutubeId } from './index-c7e2ac95.js';
import Breadcrumbs from './Breadcrumbs.js';
import MasterDeck from './MasterDeck.js';
import VideoSeriesCard from './VideoSeriesCard.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-95db387d.js';
import './web.dom.iterable-3fffc027.js';
import './_library-528f1934.js';
import './_set-species-7d3317b7.js';
import './_iter-detect-2f89237f.js';
import './_is-array-68c79b29.js';
import './extends-2f4448b8.js';
import './slicedToArray-72ed566b.js';
import 'react-bootstrap/Breadcrumb';
import './toConsumableArray-e6f28e5c.js';
import './inherits-96c84cbd.js';
import './_object-sap-14bd8e96.js';
import './define-property-433c51d3.js';
import './index-5cc7b406.js';
import 'prop-types';
import 'react-bootstrap/Container';
import 'react-bootstrap/Row';
import 'react-bootstrap/Col';
import 'react-bootstrap/Card';
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-6e892331.js';
import './AdSlot.js';
import './Beam.js';
import './stringify-1e2a5946.js';
import './Segment.js';
import './main-dde1592e.js';
import './ADInfeed-b05502a1.js';
import './index-755f2cc2.js';
import './urlFor.js';
import './style-inject.es-1f59c1d0.js';

var _this = undefined;

var VideoSeriesLandingPage = function VideoSeriesLandingPage(props) {
  var summary = props.summary,
      client = props.client,
      posts = props.posts,
      _props$variant = props.variant,
      variant = _props$variant === undefined ? 'left' : _props$variant,
      _props$defaultImage = props.defaultImage,
      defaultImage = _props$defaultImage === undefined ? '/placeholder.jpg' : _props$defaultImage,
      mapping = props.mapping,
      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,
      rightItems = props.rightItems,
      brandInsightAd = props.brandInsightAd,
      _props$showBI = props.showBI,
      showBI = _props$showBI === undefined ? false : _props$showBI,
      _props$lgInfeedAd = props.lgInfeedAd,
      lgInfeedAd = _props$lgInfeedAd === undefined ? false : _props$lgInfeedAd;

  return React__default.createElement(
    'div',
    null,
    summary && React__default.createElement(
      'div',
      { style: { fontSize: '1rem' }, className: 'series-summary px-1 my-4' },
      summary
    ),
    React__default.createElement(Breadcrumbs, null),
    posts && React__default.createElement(MasterDeck, {
      deck: VideoSeriesCard,
      variant: variant,
      client: client,
      defaultImage: defaultImage,
      mapping: mapping,
      dataRecord: posts,
      query: query,
      params: params,
      currentPage: currentPage,
      pageview: pageview,
      autoScroll: autoScroll,
      rightItems: rightItems,
      brandInsightAd: brandInsightAd,
      showBI: showBI,
      lgInfeedAd: lgInfeedAd
    })
  );
};

VideoSeriesLandingPage.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 today, urlQuery, seriesName, currentPage, start, params, query, posts, seriesTitle, summary, url;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            today = moment().utc().format();
            urlQuery = context.query;
            seriesName = urlQuery.series;
            currentPage = urlQuery.page ? parseInt(urlQuery.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    && dateTime(published) <= dateTime(now()) \n    && references(\'' + taxonomyId + '\') \n    && is_visible == true \n    && url.current == \'' + seriesName + '\'\n  ][$from...$to] | order(published desc) {\n\t\ttitle,\n\t\tsummary,\n\t\tpublished,\n\t\tthumbnail,\n\t\turl,\n\t\ttaxonomy,\n\t\tbody[_type == "youtubeGallery"]\n\t}';
            _context.next = 9;
            return client.fetch(query, params);

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


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

              seriesTitle = posts[0].title;
              summary = posts[0].summary;
              posts = posts[0].body[0].videos.filter(function (video) {
                if ((video.is_visible === true || !video.hasOwnProperty('is_visible')) && (today >= video.published || !video.hasOwnProperty('published'))) {
                  return video;
                }
              });
              //start youtube thumbnail fix
              posts.map(function (post, index) {
                if (post.thumbnail && _typeof(post.thumbnail) !== 'object' || !post.thumbnail) {
                  var id = getYoutubeId(post.url);
                  var imageURL = 'https://img.youtube.com/vi/' + id + '/hqdefault.jpg';
                  return post['thumbnail'] = imageURL, post['url'] = {
                    current: url + (index + 1)
                  };
                }
                return post['url'] = {
                  current: url + (index + 1)
                };
              });
              //end
            }
            return _context.abrupt('return', { posts: posts, query: query, params: params, seriesTitle: seriesTitle, summary: summary, seriesName: seriesName });

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

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

export { VideoSeriesLandingPage as default };
