'use strict';

var asyncToGenerator = require('./asyncToGenerator-58c289d9.js');
var _extends = require('./extends-29bdbc6d.js');
var slicedToArray = require('./slicedToArray-5d1bc3b3.js');
var React = require('react');
var Head = require('next/head');
var Router = require('next/router');
var stringify = require('./stringify-c9ac1214.js');
var toConsumableArray = require('./toConsumableArray-ddb70795.js');
var moment = require('./moment-aca40de1.js');
var BlockContent = require('./BlockContent-36e54d77.js');
var main = require('./main-025fdc78.js');
require('react-bootstrap/Dropdown');
var Form = require('react-bootstrap/Form');
var FormControl = require('react-bootstrap/FormControl');
var Button = require('react-bootstrap/Button');
var visibilitySensor = require('./visibility-sensor-eb2c5b69.js');
var SocialShare = require('./SocialShare.js');
var getSerializers = require('./index-6741b269.js');
var AdSlot = require('./AdSlot.js');
var SeriesSlider = require('./SeriesSlider-4862d8c4.js');
var getTargeting = require('./getTargeting-be6168ad.js');
var getKeywords = require('./getKeywords.js');
var urlFor = require('./urlFor.js');
var _typeof = require('./typeof-88a668c5.js');
var index_esm = require('./index.esm-05850a2f.js');
var styleInject_es = require('./style-inject.es-dcee06b6.js');
require('./index-eadd5035.js');
var disqusReact = require('disqus-react');
var keys = require('./keys-7f2c2108.js');
var index_es = require('./index.es-f3e47207.js');
var index = require('./index-fc2f1ca2.js');
var getRelatedArticle = require('./getRelatedArticle.js');
var getQuery = require('./getQuery.js');
var getSeriesDetail = require('./getSeriesDetail.js');
require('./_commonjsHelpers-06173234.js');
require('./es6.string.iterator-c2573ffd.js');
require('./_to-object-6de10e57.js');
require('./web.dom.iterable-46657b5c.js');
require('./_library-dd23b178.js');
require('./core.get-iterator-method-f474eacc.js');
require('./_iter-detect-55a5657a.js');
require('./_object-pie-083f2dd6.js');
require('prop-types');
require('./index-efca863c.js');
require('react-dom');
require('react-share');
require('react-bootstrap');
require('./index-187c967e.js');
require('./util-6f784d85.js');
require('./Beam.js');
require('./Segment.js');
require('./brightcove-react-player-loader.es-a195642e.js');
require('./GroupDeck.js');
require('./smoothscroll-99df7f93.js');
require('./_is-array-6128bd56.js');
require('./_object-to-array-8fe5a54f.js');
require('react-bootstrap/Pagination');
require('./entities-3f9d0f2f.js');
require('react-bootstrap/Row');
require('react-bootstrap/Col');
require('./inherits-c2065b95.js');
require('./_object-sap-a175b4a9.js');
require('./define-property-c88be878.js');
require('./index.esm-974f47d9.js');
require('./iconBase-68959171.js');
require('react-bootstrap/Figure');
require('./debounce-d4a2369b.js');
require('./isSymbol-03abbdf0.js');
require('./toNumber-5e1fac58.js');
require('./events-1b438fe7.js');
require('./index-bd6c9f56.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
var Form__default = /*#__PURE__*/_interopDefaultLegacy(Form);
var FormControl__default = /*#__PURE__*/_interopDefaultLegacy(FormControl);
var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);

var getArticleSummary = function getArticleSummary(article) {
  if (article.summary && article.summary.length > 0) {
    return article.summary;
  } else {
    return false;
  }
};

var getDocumentGroupUrl = function getDocumentGroupUrl(docGroup) {
  if (!docGroup) {
    return null;
  }
  var url = void 0;

  if (docGroup.path && docGroup.path.includes('/') && (!docGroup.parent || !docGroup.parent.parent)) {
    return '/' + docGroup.path;
  }
  // Checking if Parent has Parent
  if (docGroup.path && docGroup.path.includes('/') && docGroup.parent && docGroup.parent.parent) {
    if (docGroup.path.includes(docGroup.parent.identifier.current)) {
      return '/' + docGroup.parent.parent.identifier.current + '/' + docGroup.path;
    } else {
      return '/' + docGroup.parent.parent.identifier.current + '/' + docGroup.parent.identifier.current + '/' + docGroup.path;
    }
  }

  if (docGroup.parent) {
    url = '/' + docGroup.parent.identifier.current;
    if (docGroup.parent.parent && docGroup.parent.parent.name) {
      url = '/' + docGroup.parent.parent.identifier.current + url;
    }
  }

  if (!docGroup.thumbnail) ;
  url = url + '/' + docGroup.path;

  return url;
};

var getDocumentGroupName = function getDocumentGroupName(docGroup) {
  var name = void 0;
  if (!docGroup) {
    return null;
  }

  if (docGroup.parent) {
    name = docGroup.parent.name;

    if (docGroup.parent.parent && docGroup.parent.parent.name) {
      name = docGroup.parent.parent.name + ' | ' + name;
    }
  }

  //if (!docGroup.thumbnail) {
  name = name + ' | <b>' + docGroup.name + '</b>';
  //}

  return name;
};

var DocumentGroup = function DocumentGroup(_ref) {
  var article = _ref.article,
      client = _ref.client;

  if (!article.documentGroup || article.documentGroup.isShow === false || article.documentGroup.isSeries) {
    return null;
  }

  var name = getDocumentGroupName(article.documentGroup);
  var url = getDocumentGroupUrl(article.documentGroup);
  var thumbnailUrl = false;

  if (article.documentGroup.thumbnail) {
    thumbnailUrl = urlFor({ client: client, source: article.documentGroup.thumbnail });
  }

  return React__default['default'].createElement(
    'a',
    {
      href: url,
      className: 'doc-group',
      style: { display: 'flex', flexDirection: 'column', padding: '0 1rem', justifyContent: thumbnailUrl ? 'center' : 'flex-start', alignItems: 'center' } },
    thumbnailUrl && React__default['default'].createElement('img', { style: { maxWidth: '220px', maxHeight: '100px', marginTop: '1rem' }, src: thumbnailUrl, alt: name }),
    !thumbnailUrl && React__default['default'].createElement('p', {
      style: { maxWidth: '315px', margin: '0', color: 'var(--primary)', textAlign: thumbnailUrl ? 'center' : main.main_43 ? 'left' : 'right', marginTop: '.25rem' },
      dangerouslySetInnerHTML: { __html: name } }),
    main.main_43 && !thumbnailUrl && React__default['default'].createElement(
      'style',
      { jsx: 'true' },
      '\n          a.doc-group {\n            display: block !important;\n            padding: 0 !important;\n          }\n        '
    )
  );
};

var findIndex = function findIndex(arr) {
  var indexes = [];
  if ((typeof arr === 'undefined' ? 'undefined' : _typeof._typeof(arr)) === 'object') {
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = slicedToArray._getIterator(arr), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var ele = _step.value;

        if (ele['_type'] === 'block' && ele.children.some(function (child) {
          return child.text.trim().length > 0;
        }) && ele['listItem'] !== 'bullet' &&
        //  To skip li tags when setting contextual native ads
        ele['listItem'] !== 'number' && ele['style'] === 'normal' || ele['_type'] === 'figure') {
          indexes.push(arr.indexOf(ele));
        }
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }
  }
  return indexes;
};

var ISI = function ISI(props) {
  var children = props.children;

  var _useState = React.useState(false),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      active = _useState2[0],
      setActive = _useState2[1];

  var _useState3 = React.useState(false),
      _useState4 = slicedToArray._slicedToArray(_useState3, 2),
      bottomOfArticle = _useState4[0],
      setbottomOfArticle = _useState4[1];

  var isi = React.useRef();

  React.useEffect(function () {
    if (active) {
      var offset = '5rem';
      var nav = document.getElementsByTagName('header');
      if (nav && nav.length > 0) {
        offset = nav[0].offsetHeight + 'px';
      }
      isi.current.style.maxHeight = 'calc(100% - ' + offset + ')';
      isi.current.style.overflowY = 'scroll';
    } else {
      isi.current.style.maxHeight = '';
      isi.current.style.overflowY = '';
    }
  }, [active]);
  React.useEffect(function () {
    var detectBottomOfArticle = function detectBottomOfArticle() {
      var article_body = document.getElementById('article__block');
      var isi = document.getElementById('isi');
      var articleBottomPosition = article_body.getBoundingClientRect().bottom - window.innerHeight;
      console.log(articleBottomPosition, bottomOfArticle);
      if (articleBottomPosition < 30 && !isi.classList.contains('in-view')) {
        setbottomOfArticle(true);
      }
      if (articleBottomPosition > 60 && isi.classList.contains('in-view')) {
        setbottomOfArticle(false);
      }
    };
    window.addEventListener('scroll', detectBottomOfArticle);
    return function () {
      return window.removeEventListener('scroll', detectBottomOfArticle);
    };
  }, []);

  React.useEffect(function () {
    var isi = document.getElementById('isi');
    if (bottomOfArticle) {
      toggleSticky(true);
      isi.classList.add('in-view');
      if (active) {
        setActive(false);
      }
    }
    if (!bottomOfArticle) {
      toggleSticky(false);
      isi.classList.remove('in-view');
    }
  }, [bottomOfArticle]);

  var toggleSticky = function toggleSticky(sticky) {
    var isiToggle = document.getElementById('isiToggle');
    var isiContent = document.getElementById('isiContent');
    var isi = document.getElementById('isi');
    if (sticky) {
      isi.style.bottom = '-200px';
      setTimeout(function () {
        isi.style.maxHeight = 'unset';
        isi.style.position = 'relative';
        isi.style.boxShadow = 'none';
        isi.style.zIndex = '1';
        isi.style.marginTop = '-25rem';
        isi.style.marginBottom = '15rem';
        isiToggle.style.display = 'none';
        isiContent.style.padding = '0';
      }, 300);
    } else if (!sticky) {

      isi.style.marginBottom = '0';
      isi.style.maxHeight = '12rem';
      isi.style.position = 'fixed';
      isi.style.boxShadow = '0 0 1rem 0 rgba(0, 0, 0, 0.5)';
      isi.style.zIndex = '99999';

      isiToggle.style.display = 'block';
      isiContent.style.padding = '1rem';
      setTimeout(function () {
        isi.style.bottom = '0';
        isi.style.marginTop = '0';
      }, 300);
    }
  };
  return React__default['default'].createElement(
    React__default['default'].Fragment,
    null,
    React__default['default'].createElement(
      'div',
      { id: 'isi', ref: isi },
      React__default['default'].createElement(
        'div',
        { id: 'isiContent' },
        React__default['default'].createElement(
          'div',
          { onClick: function onClick() {
              return setActive(function (prev) {
                return !prev;
              });
            }, id: 'isiToggle' },
          active ? React__default['default'].createElement(
            'p',
            null,
            'Close ',
            React__default['default'].createElement(index_esm.FaMinus, null)
          ) : React__default['default'].createElement(
            'p',
            null,
            'See More ',
            React__default['default'].createElement(index_esm.FaPlus, null)
          )
        ),
        children
      )
    ),
    React__default['default'].createElement(
      'style',
      { jsx: true },
      '\n        #isi {\n          position: fixed;\n          z-index: 9999999;\n          bottom: 0;\n          left: 0;\n          max-height: 12rem;\n          background-color: #ffffff;\n          overflow-x: hidden;\n          overflow-y: hidden;\n          width: 100%;\n          box-shadow: 0 0 1rem 0 rgba(0, 0, 0, 0.5);\n          transition: bottom .5s ease , margin-top .3s, max-height .2s;\n        }\n        #isiContent {\n          width: 100%;\n          max-width: 1000px;\n          margin-left: auto;\n          margin-right: auto;\n          position: relative;\n          padding: 1rem;\n          font-size: 1rem;\n        }\n        #isi::-webkit-scrollbar {\n          display: none;\n        }\n        #isiToggle {\n          position: absolute;\n          top: 0;\n          right: 0;\n          padding: 1rem;\n          font-weight: bold;\n          cursor: pointer;\n          font-size: 1rem;\n        }\n        #isiToggle p {\n          margin: 0;\n        }\n      '
    )
  );
};

var css = ".RelatedArticles-module_mediaContainer__10h9k {\n  display: flex;\n  flex-direction: row;\n  flex-wrap: nowrap;\n  margin: 0 -1rem;\n}\n.RelatedArticles-module_mediaCard__3wQbn {\n  margin: 0 1rem 1rem;\n  width: calc(33% - 1rem);\n  display: column;\n  flex-direction: row;\n  margin-bottom: 0.75rem;\n  padding-bottom: 0.75rem;\n  border-bottom: none;\n}\n.RelatedArticles-module_mediaCard__3wQbn:last-child {\n  border-bottom: none;\n}\n.RelatedArticles-module_cardTitle__3P-Ib {\n  font-weight: bold;\n  color: #252525;\n  margin-bottom: 0.25rem;\n  font-size: 15px;\n}\n.RelatedArticles-module_authorListing__1EFg4 span.RelatedArticles-module_text-muted__3b0zX {\n  color: #000;\n  font-weight: bold;\n}\n.RelatedArticles-module_cardDate__1wOR5 {\n  color: var(--dark);\n  display: block;\n  background: #fff !important;\n  margin-bottom: 0;\n}\n.RelatedArticles-module_imgWrapper__5Jx_4 {\n  display: block;\n  text-align: center;\n  margin-bottom: 0.5rem;\n}\n.RelatedArticles-module_imgWrapper__5Jx_4 img {\n  height: 135px;\n  width: 100%;\n  object-fit: cover;\n  object-position: center;\n}\n@media screen and (max-width: 1064px) {\n}\n@media screen and (max-width: 968px) {\n  .RelatedArticles-module_mediaContainer__10h9k {\n    flex-wrap: wrap;\n  }\n  .RelatedArticles-module_imgWrapper__5Jx_4 {\n    display: none;\n  }\n  .RelatedArticles-module_mediaCard__3wQbn {\n    width: 100%;\n    margin-bottom: 0.5rem;\n    padding: 0;\n  }\n  .RelatedArticles-module_cardTitle__3P-Ib {\n    font-size: 0.75rem;\n    margin-bottom: 0;\n  }\n}\n";
var styles = { "mediaContainer": "RelatedArticles-module_mediaContainer__10h9k", "mediaCard": "RelatedArticles-module_mediaCard__3wQbn", "cardTitle": "RelatedArticles-module_cardTitle__3P-Ib", "authorListing": "RelatedArticles-module_authorListing__1EFg4", "text-muted": "RelatedArticles-module_text-muted__3b0zX", "cardDate": "RelatedArticles-module_cardDate__1wOR5", "imgWrapper": "RelatedArticles-module_imgWrapper__5Jx_4" };
styleInject_es.styleInject(css);

var RelatedArticle = function RelatedArticle(_ref) {
  var articles = _ref.articles,
      client = _ref.client,
      fallbackImage = _ref.fallbackImage,
      _ref$showRelatedArtic = _ref.showRelatedArticleFallbackImage,
      showRelatedArticleFallbackImage = _ref$showRelatedArtic === undefined ? true : _ref$showRelatedArtic;

  if (!articles || articles.length == 0 || !articles[0]) {
    return null;
  }
  return React__default['default'].createElement(
    'div',
    { className: styles.mediaContainer },
    articles.map(function (article, index) {
      return React__default['default'].createElement(
        'div',
        { id: 'related-card', key: index, className: styles.mediaCard },
        React__default['default'].createElement(
          'a',
          { className: styles.imgWrapper, href: '/view/' + (article.url ? article.url.current : '') },
          article.thumbnail ? React__default['default'].createElement('img', {
            style: { objectFit: 'cover', objectPosition: 'center' },
            src: article.thumbnail && urlFor({ client: client, source: article.thumbnail.asset, imageWidth: 250 }),
            alt: article.title
          }) : React__default['default'].createElement(
            React__default['default'].Fragment,
            null,
            fallbackImage && showRelatedArticleFallbackImage && React__default['default'].createElement('img', { src: fallbackImage, alt: 'website logo', style: { objectFit: 'contain' } })
          )
        ),
        React__default['default'].createElement(
          'div',
          { className: styles.mediaBody },
          React__default['default'].createElement(
            'a',
            { href: '/view/' + (article.url ? article.url.current : '') },
            React__default['default'].createElement(
              'div',
              { className: styles.cardTitle },
              article.title
            )
          )
        )
      );
    })
  );
};

var getSocialShareDisableFlag = function getSocialShareDisableFlag(article) {
  //Need to check Taxonomy, DocumentGroup, and Authors for showSocialShare
  var showSocialShare = true;

  if (article.content_placement && article.content_placement.length > 0) {
    //loop through each
    article.content_placement.forEach(function (category) {
      if (category.showSocialShare === false) {
        showSocialShare = false;
      }
    });
  }
  if (article.authorDetails && article.authorDetails.length > 0) {
    article.authorDetails.forEach(function (author) {
      if (author.showSocialShare === false) {
        showSocialShare = false;
      }
    });
  }
  if (article.documentGroup && article.documentGroup.length > 0) {
    article.documentGroup.forEach(function (docGroup) {
      if (docGroup.showSocialShare === false) {
        showSocialShare = false;
      }
    });
  }
  if (article.documentGroupMapping && article.documentGroupMapping.length > 0) {
    article.documentGroupMapping.forEach(function (docGroup) {
      if (docGroup.showSocialShare === false) {
        showSocialShare = false;
      }
    });
  }

  return showSocialShare;
};

var Article = React.forwardRef(function (props, ref) {
  var onVote = function () {
    var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee(nodeKey, selectedChoice) {
      var response, result;
      return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return fetch('/api/polls/vote', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: stringify._JSON$stringify({ articleId: props.article._id, nodeKey: nodeKey, selectedChoice: selectedChoice, body: articleBody })
              });

            case 2:
              response = _context.sent;

              if (!response.ok) {
                _context.next = 11;
                break;
              }

              _context.next = 6;
              return response.json();

            case 6:
              result = _context.sent;

              setArticleBody(result.body);

              console.log('Voted successfully');
              _context.next = 12;
              break;

            case 11:
              console.log('Unable to vote!');

            case 12:
            case 'end':
              return _context.stop();
          }
        }
      }, _callee, this);
    }));

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

  var article = props.article,
      Ads = props.Ads,
      showRelatedArticles = props.showRelatedArticles,
      _props$hideFBShare = props.hideFBShare,
      hideFBShare = _props$hideFBShare === undefined ? false : _props$hideFBShare,
      _props$hidePinterestS = props.hidePinterestShare,
      hidePinterestShare = _props$hidePinterestS === undefined ? false : _props$hidePinterestS,
      onChangeArticle = props.onChangeArticle,
      _props$showSocialShar = props.showSocialShare,
      showSocialShare = _props$showSocialShar === undefined ? true : _props$showSocialShar;
  var client = props.client,
      pageview = props.pageview,
      videoAccountIDs = props.videoAccountIDs,
      drupalLeadSettings = props.drupalLeadSettings,
      currentPage = props.currentPage,
      _props$article = props.article,
      title = _props$article.title,
      _props$article$passwo = _props$article.passwordLock,
      passwordLock = _props$article$passwo === undefined ? false : _props$article$passwo,
      authorDetails = _props$article.authorDetails,
      pageNumber = _props$article.pageNumber,
      published = _props$article.published,
      _props$article$showPu = _props$article.showPublished,
      showPublished = _props$article$showPu === undefined ? true : _props$article$showPu,
      body = _props$article.body,
      thumbnail = _props$article.thumbnail,
      content_placement = _props$article.content_placement,
      _props$article$url = _props$article.url;
  _props$article$url = _props$article$url === undefined ? {
    current: ''
  } : _props$article$url;
  var url = _props$article$url.current,
      issue = _props$article.issue,
      source = _props$article.source,
      documentGroupMapping = _props$article.documentGroupMapping,
      issueGroup = _props$article.issueGroup,
      showIsi = _props$article.showIsi,
      isi = _props$article.isi,
      _props$article$displa = _props$article.display_summary,
      display_summary = _props$article$displa === undefined ? true : _props$article$displa,
      regionalPages = props.regionalPages,
      nationalPage = props.nationalPage,
      ISIContent = props.ISIContent,
      shareOptions = props.shareOptions,
      cpModificationRequired = props.cpModificationRequired,
      authorPrefix = props.authorPrefix,
      _props$lgContextAd = props.lgContextAd,
      lgContextAd = _props$lgContextAd === undefined ? false : _props$lgContextAd,
      queueData = props.queueData,
      _props$sponsoredFlag = props.sponsoredFlag,
      sponsoredFlag = _props$sponsoredFlag === undefined ? false : _props$sponsoredFlag,
      _props$authorImgHeigh = props.authorImgHeight,
      authorImgHeight = _props$authorImgHeigh === undefined ? 270 : _props$authorImgHeigh;
      props.active;
      var containerHeight = props.containerHeight,
      _props$refreshFlag = props.refreshFlag,
      refreshFlag = _props$refreshFlag === undefined ? false : _props$refreshFlag,
      disqusConfig = props.disqusConfig,
      showDisqus = props.showDisqus;

  var targeting = getTargeting.getTargeting(props);

  //if showSocialShare is not disabled for entire site, check article taxonomy, docgroup, authors for showSocialShare === false
  if (showSocialShare) {
    showSocialShare = getSocialShareDisableFlag(props.article);
  }

  //If sponsored flag, disable contextual ads
  if (sponsoredFlag) {
    article.contextualVideoAD = false;
    article.contextualAD = false;
    showRelatedArticles = false;
  }
  if (article.disableRelatedContent) {
    showRelatedArticles = false;
  }
  //This was being done in ArticleQueue2 which wasnt effecting articles excluded from infinite scroll, moved inside article component
  if (!sponsoredFlag && Ads.getVideoContextualAD) {
    article.contextualVideoAD = Ads.getVideoContextualAD(getTargeting.getTargeting(props, 'in-context_video'));
  }
  if (!sponsoredFlag && Ads.getNativeContextualAD) {
    article.contextualAD = Ads.getNativeContextualAD(getTargeting.getTargeting(props, 'native-ad'));
  }

  var _useState = React.useState(null),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      contextualADFlag = _useState2[0],
      setContextualADFlag = _useState2[1];
  //  Setting new Flag 'visibleFlag' to know when the article is visible so that new contextual ad can be appended into DOM.


  var _useState3 = React.useState(false),
      _useState4 = slicedToArray._slicedToArray(_useState3, 2),
      visibleFlag = _useState4[0],
      setVisibleFlag = _useState4[1];

  var summary = getArticleSummary(props.article);

  var _useState5 = React.useState(1),
      _useState6 = slicedToArray._slicedToArray(_useState5, 2),
      auth = _useState6[0],
      setAuth = _useState6[1];

  var _useState7 = React.useState(''),
      _useState8 = slicedToArray._slicedToArray(_useState7, 2),
      passwordKey = _useState8[0],
      setPasswordKey = _useState8[1];

  var _useState9 = React.useState(body),
      _useState10 = slicedToArray._slicedToArray(_useState9, 2),
      articleBody = _useState10[0],
      setArticleBody = _useState10[1];

  var _useState11 = React.useState(true),
      _useState12 = slicedToArray._slicedToArray(_useState11, 2);
      _useState12[0];
      var setPreviewAd = _useState12[1];

  React.useEffect(function () {
    var path = window && window.location && window.location.search;
    // Setting flag for Ad-preview URLs
    setPreviewAd(path.split('&').some(function (param) {
      return param.includes('creativeId');
    }));
  }, []);

  var isCutomPage = function isCutomPage(article) {
    var url = article.url.current;

    if (regionalPages || nationalPage) {
      return regionalPages.includes(url) || nationalPage === url;
    } else {
      return false;
    }
  };
  var renderAuthorBiography = function renderAuthorBiography(biography) {
    if (biography) {
      return React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
        serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, false, contextualADFlag),
        blocks: [biography]
      }, client.config()));
    }
  };
  var renderIsiContent = function renderIsiContent(article) {
    var url = article.url.current;

    if (regionalPages && ISIContent && regionalPages.includes(url)) {
      return React__default['default'].createElement(ISIContent, null);
    } else if (nationalPage === url && ISIContent) {
      return React__default['default'].createElement(ISIContent, { national: true });
    }
    return null;
  };

  var RelevantTopics = function RelevantTopics() {
    if (content_placement && content_placement.length > 0 || documentGroupMapping && documentGroupMapping.length > 0) {
      var relatedLinks = [];
      if (documentGroupMapping && documentGroupMapping.length > 0) {
        documentGroupMapping.forEach(function (documentGroup) {
          if (documentGroup.parent) {
            relatedLinks = [].concat(toConsumableArray._toConsumableArray(relatedLinks), [{ label: documentGroup.name, href: cpModificationRequired ? getDocumentGroupUrl(documentGroup) : '/' + documentGroup.path }]);
          }
        });
      }
      if (content_placement && content_placement.length > 0) {
        content_placement.filter(function (item) {
          return item.path !== 'news';
        }).forEach(function (cp) {
          var cp_url = cpModificationRequired ? getTargeting.getContentPlacementUrl(cp) : cp.path;
          var href = '/' + cp_url;
          relatedLinks = [].concat(toConsumableArray._toConsumableArray(relatedLinks), [{ label: cp.name, href: href }]);
        });
      }
      if (issueGroup && issueGroup.name && issueGroup.identifier && issueGroup.identifier.current && issueGroup.parent && issueGroup.parent.identifier && issueGroup.parent.identifier.current) {
        var _props$Settings$issue = props.Settings.issueMapping,
            issueMapping = _props$Settings$issue === undefined ? '/publications' : _props$Settings$issue;

        relatedLinks = [].concat(toConsumableArray._toConsumableArray(relatedLinks), [{ label: issueGroup.name, href: issueMapping + '/' + issueGroup.parent.identifier.current + '/' + issueGroup.identifier.current }]);
      }
      if (relatedLinks && relatedLinks.length > 0) {
        return React__default['default'].createElement(
          'div',
          null,
          relatedLinks.map(function (relatedLink, index) {
            return React__default['default'].createElement(
              'span',
              { key: index, className: 'related-link' },
              React__default['default'].createElement(
                'a',
                { className: 'related-links', style: { color: 'blue' }, href: relatedLink.href },
                relatedLink.label
              ),
              React__default['default'].createElement(
                'style',
                { jsx: 'true' },
                '\n                      .related-link:not(:first-child):before {\n                        content: \' | \';\n                      }\n                    '
              )
            );
          })
        );
      }
      return null;
    }
    return null;
  };

  var RelatedContent = function RelatedContent() {
    return React__default['default'].createElement(
      'section',
      { id: 'related-content-section', className: 'my-1' },
      (article.relatedArticle || RelevantTopics()) && React__default['default'].createElement(
        'p',
        { className: 'mb-0' },
        React__default['default'].createElement(
          'b',
          null,
          'Related Content:'
        )
      ),
      React__default['default'].createElement(RelevantTopics, null),
      React__default['default'].createElement(
        'div',
        { className: 'pt-2' },
        React__default['default'].createElement(RelatedArticle, {
          articles: article.relatedArticle,
          client: client,
          fallbackImage: props.Settings.logo,
          showRelatedArticleFallbackImage: props.showRelatedArticleFallbackImage
        })
      )
    );
  };

  var form = function form() {
    return React__default['default'].createElement(
      React__default['default'].Fragment,
      null,
      React__default['default'].createElement(
        Head__default['default'],
        null,
        React__default['default'].createElement('meta', { name: 'googlebot', content: 'noindex' })
      ),
      React__default['default'].createElement(
        'div',
        { className: 'mt-5', style: { display: 'flex', justifyContent: 'center', alignItems: 'center' } },
        React__default['default'].createElement(
          Form__default['default'],
          {
            inline: true,
            onSubmit: function onSubmit(e) {
              e.preventDefault();
            } },
          React__default['default'].createElement(FormControl__default['default'], { type: 'text', className: 'mr-sm-2', value: passwordKey, onChange: function onChange(e) {
              return setPasswordKey(e.target.value);
            }, placeholder: 'Password' }),
          React__default['default'].createElement(
            Button__default['default'],
            {
              variant: 'primary',
              onClick: function onClick() {
                if (passwordKey === props.article.password) {
                  setAuth(2);
                } else {
                  alert('Incorrect Password');
                }
              } },
            'Submit'
          )
        )
      )
    );
  };

  var renderBlockContent = function renderBlockContent(payload, meta, authorImgHeight) {
    var _payload = payload,
        body = _payload.body;

    var indexes = findIndex(body);
    var seriesInfo = checkIfMediaSeriesHasVideo(article);
    var isMediaSeries = article.documentGroup && article.documentGroup.isSeries ? true : false;
    if (indexes.length >= 2 && body.length > 3 && payload.contextualAD && payload.contextualVideoAD) {
      payload = _extends._extends({}, payload, {
        contextualAD: _extends._extends({}, payload.contextualAD, {
          slotId: (payload.contextualAD.slotId || 'contextual_ad') + '-' + payload._id
        }),
        contextualVideoAD: _extends._extends({}, payload.contextualVideoAD, {
          slotId: (payload.contextualVideoAD.slotId || 'in-context_video') + '-' + payload._id
        })
      });
      var selectedIndex = indexes[1] + 1;
      if (seriesInfo.hasVideo) {
        selectedIndex = seriesInfo.videoIndex;
      }

      var checkIsVideoAdFound = function checkIsVideoAdFound(isFound) {
        if (!isFound) {
          var parent = document.getElementById('contextual-video-ad-' + payload._id);
          parent.style.height = '0%';
          parent.style.width = '0%';
          parent.style.display = 'none';
          setContextualADFlag(false);
        } else {
          setContextualADFlag(true);
        }
      };
      return React__default['default'].createElement(
        React__default['default'].Fragment,
        null,
        React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, contextualADFlag, null, null, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: [].concat(toConsumableArray._toConsumableArray(articleBody.slice(0, selectedIndex))),
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config())),
        React__default['default'].createElement('span', { className: 'clearfix' }),
        article.documentGroup && article.documentGroup.isSeries && props.sliderData && seriesInfo.hasVideo && React__default['default'].createElement(SeriesSlider.SeriesSlider, { dataset: props.sliderData, client: client, nowPlaying: article.title, displayEpisodeNumber: true }),
        React__default['default'].createElement(
          'div',
          { id: 'contextual-native-ad-' + payload._id, className: 'contextual-native-ad' },
          React__default['default'].createElement(AdSlot, _extends._extends({}, payload.contextualAD, {
            refreshFlag: refreshFlag
            // checkIsAdFound={previewAd ? null : checkIsAdFound}
          }))
        ),
        React__default['default'].createElement('span', { className: 'clearfix' }),
        React__default['default'].createElement(
          'div',
          { id: 'contextual-video-ad-' + payload._id, className: 'contextual-video-ad' },
          React__default['default'].createElement(AdSlot, _extends._extends({}, payload.contextualVideoAD, { refreshFlag: refreshFlag, checkIsAdFound: checkIsVideoAdFound }))
        ),
        React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, null, null, null, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: [].concat(toConsumableArray._toConsumableArray(articleBody.slice(selectedIndex))),
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config()))
      );
    } else if (indexes.length >= 2 && body.length >= 3 && payload.contextualAD && !payload.contextualVideoAD) {
      payload = _extends._extends({}, payload, {
        contextualAD: _extends._extends({}, payload.contextualAD, {
          slotId: (payload.contextualAD.slotId || 'contextual_ad') + '-' + payload._id,
          className: 'ADFluid',
          //  Fetching new contextual targeting based on the current active article.
          targeting: getTargeting.getTargeting(props, 'native-ad'),
          // Adding new ad size for large contextual ad for desktop screen width >= 1400
          sizes: lgContextAd ? [[728, 90], 'fluid', [300, 100]] : ['fluid', [300, 100]],
          sizeMapping: lgContextAd ? [{
            viewport: [1400, 0],
            sizes: [[728, 90], 'fluid', [300, 100]]
          }, { viewport: [0, 0], sizes: ['fluid', [300, 100]] }] : { viewport: [0, 0], sizes: ['fluid', [300, 100]] }
        })
      });
      var _selectedIndex = indexes[1] + 1;
      if (seriesInfo.hasVideo) {
        _selectedIndex = seriesInfo.videoIndex;
      }
      return React__default['default'].createElement(
        React__default['default'].Fragment,
        null,
        React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, contextualADFlag, null, null, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: [].concat(toConsumableArray._toConsumableArray(articleBody.slice(0, _selectedIndex))),
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config())),
        contextualADFlag && React__default['default'].createElement('span', { className: 'clearfix' }),
        article.documentGroup && article.documentGroup.isSeries && props.sliderData && seriesInfo.hasVideo && React__default['default'].createElement(SeriesSlider.SeriesSlider, { dataset: props.sliderData, client: client, nowPlaying: article.title, displayEpisodeNumber: true }),
        (visibleFlag || queueData && queueData.length === 1 || !props.infiniteScroll) && React__default['default'].createElement(
          'div',
          { id: 'contextual-native-ad-' + payload._id, className: 'contextual-native-ad' },
          React__default['default'].createElement(AdSlot, _extends._extends({}, payload.contextualAD, {
            refreshFlag: refreshFlag
            // checkIsAdFound={previewAd ? null : checkIsAdFound}
          }))
        ),
        contextualADFlag && React__default['default'].createElement('span', { className: 'clearfix' }),
        React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, null, null, null, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: [].concat(toConsumableArray._toConsumableArray(articleBody.slice(_selectedIndex))),
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config()))
      );
    } else if (indexes.length >= 2 && body.length > 3 && payload.contextualVideoAD && !payload.contextualAD) {
      payload = _extends._extends({}, payload, {
        contextualVideoAD: _extends._extends({}, payload.contextualVideoAD, {
          slotId: (payload.contextualVideoAD.slotId || 'in-context_video') + '-' + payload._id
        })
      });
      var _selectedIndex2 = indexes[1] + 1;
      if (seriesInfo.hasVideo) {
        _selectedIndex2 = seriesInfo.videoIndex;
      }
      var _checkIsAdFound2 = function _checkIsAdFound2(isFound) {
        if (!isFound) {
          var parent = document.getElementById('contextual-video-ad-' + payload._id);
          parent.style.height = '0%';
          parent.style.width = '0%';
          parent.style.display = 'none';
          setContextualADFlag(false);
        } else {
          if (body && body[1] && body[1]._type === 'figure') {
            setContextualADFlag(true);
          }
        }
      };

      return React__default['default'].createElement(
        React__default['default'].Fragment,
        null,
        React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, contextualADFlag, null, null, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: [].concat(toConsumableArray._toConsumableArray(articleBody.slice(0, _selectedIndex2))),
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config())),
        React__default['default'].createElement('span', { className: 'clearfix' }),
        article.documentGroup && article.documentGroup.isSeries && props.sliderData && seriesInfo.hasVideo && React__default['default'].createElement(SeriesSlider.SeriesSlider, { dataset: props.sliderData, client: client, nowPlaying: article.title, displayEpisodeNumber: true }),
        React__default['default'].createElement(
          'div',
          { id: 'contextual-video-ad-' + payload._id, className: 'contextual-video-ad' },
          React__default['default'].createElement(AdSlot, _extends._extends({}, payload.contextualVideoAD, { refreshFlag: refreshFlag, checkIsAdFound: _checkIsAdFound2 }))
        ),
        React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, null, null, null, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: [].concat(toConsumableArray._toConsumableArray(articleBody.slice(_selectedIndex2))),
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config()))
      );
    } else {
      var _selectedIndex3 = indexes[1] + 1;
      if (seriesInfo.hasVideo) {
        _selectedIndex3 = seriesInfo.videoIndex;
      }

      return React__default['default'].createElement(
        'div',
        null,
        React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, false, null, props.article.Ads, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: article.documentGroup && article.documentGroup.isSeries ? [].concat(toConsumableArray._toConsumableArray(articleBody.slice(0, _selectedIndex3))) : articleBody,
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config())),
        article.documentGroup && article.documentGroup.isSeries && props.sliderData && seriesInfo.hasVideo && React__default['default'].createElement(SeriesSlider.SeriesSlider, { dataset: props.sliderData, client: client, nowPlaying: article.title, displayEpisodeNumber: true }),
        article.documentGroup && article.documentGroup.isSeries && React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, isMediaSeries, null, null, null, targeting, article, meta, authorPrefix, authorImgHeight),
          blocks: [].concat(toConsumableArray._toConsumableArray(articleBody.slice(_selectedIndex3))),
          imageOptions: { w: 320, h: 240, fit: 'max' }
        }, client.config()))
      );
    }
  };

  var checkIfVideoSeries = function checkIfVideoSeries(article) {
    if (!article || !article.body) {
      return false;
    }

    for (var i = 0; i < article.body.length; i++) {
      var block = article.body[i];
      if (block._type === 'youtubeGallery') {
        return true;
      }
    }

    return false;
  };
  var checkIfMediaSeriesHasVideo = function checkIfMediaSeriesHasVideo(article) {
    var seriesInfo = { hasVideo: false, videoIndex: 0 };
    if (!article || !article.body) {
      return false;
    }

    for (var i = 0; i < article.body.length; i++) {
      var block = article.body[i];
      if (block._type == 'video' || block._type == 'youtube' || block._type == 'audio') {
        seriesInfo.hasVideo = true;
        seriesInfo.videoIndex = i + 1;
      }
    }

    return seriesInfo;
  };

  var detail = function detail() {
    var shareVia = shareOptions.shareVia,
        shareSubject = shareOptions.shareSubject,
        twitterSiteName = shareOptions.twitterSiteName,
        shareImageDefault = shareOptions.shareImageDefault,
        shareBaseUrl = shareOptions.shareBaseUrl;
        shareOptions.shareSiteTitle;

    var shareUrl = shareBaseUrl + props.article.url.current;
    var shareTitle = article.title;
    var shareSummary = article.summary;
    var shareImage = thumbnail && thumbnail.asset ? urlFor({ client: props.client, source: thumbnail.asset }) : shareImageDefault;
    var siteName = props.website && props.website.title ? props.website.title : '';
    var shareKeywords = getKeywords(props.article).join(',');

    var meta = {
      shareTitle: shareTitle,
      shareSiteName: props.cache.siteSettingCache.name,
      shareSummary: shareSummary,
      shareUrl: shareUrl,
      shareImage: shareImage,
      shareVia: props.Settings.title,
      shareKeywords: shareKeywords
    };
    if (!props.infiniteScroll) {
      onChangeArticle = function onChangeArticle() {
        return null;
      };
    }
    var fetchCurrentEpisode = function fetchCurrentEpisode(sliderData, article) {
      if (!sliderData) return null;
      var episode = null;
      sliderData.forEach(function (seriesArticle, index) {
        if (seriesArticle.title === article.title) {
          episode = index + 1;
        }
      });
      return episode;
    };
    // pixels from bottom of window to change trigger visibility change
    var triggerOffset = 10;
    var isVideoSeries = checkIfVideoSeries(article);
    var episodeNumber = fetchCurrentEpisode(props.sliderData, props.article);
    var isMediaSeries = article.documentGroup && article.documentGroup.isSeries ? true : false;
    var seriesInfo = checkIfMediaSeriesHasVideo(article);

    return React__default['default'].createElement(
      React__default['default'].Fragment,
      null,
      React__default['default'].createElement(
        visibilitySensor.VisibilitySensor,
        {
          partialVisibility: true,
          offset: { bottom: triggerOffset, top: containerHeight - 80 },
          onChange: function onChange(isVisible) {
            if (isVisible && queueData && queueData.length > 1) {
              onChangeArticle(url, meta);
              setVisibleFlag(function () {
                return true;
              });
            }
          } },
        React__default['default'].createElement(
          'div',
          { id: 'article__block', ref: ref },
          React__default['default'].createElement(
            'div',
            { className: 'video-detail', style: { marginBottom: isCutomPage(props.article) || showIsi && Array.isArray(isi) && isi.length > 0 ? '15rem' : 0 } },
            isVideoSeries && renderBlockContent(article, meta, authorImgHeight),
            !isVideoSeries && React__default['default'].createElement(
              'div',
              null,
              isMediaSeries && article.documentGroup && article.documentGroup.name && React__default['default'].createElement(
                'p',
                { style: { fontSize: '14px' } },
                article.documentGroup.name,
                ' - Episode ',
                episodeNumber
              ),
              React__default['default'].createElement(
                'h1',
                { className: 'page-title', style: { fontSize: '1.9rem' } },
                title
              )
            ),
            React__default['default'].createElement(
              'div',
              { className: 'mb-3 doc-group-container', style: { display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end' } },
              React__default['default'].createElement(
                'style',
                { jsx: 'true' },
                '\n                  @media screen and (max-width: 468px) {\n                    .video-detail .doc-group-container {\n                      flex-direction: column;\n                      align-items: flex-start !important;\n                    }\n                    .video-detail .doc-group {\n                      margin-top: 2rem;\n                      width: calc(100vw - 45px);\n                      align-items: center;\n                    }\n                    .video-detail .doc-group img,\n                    .doc-group p {\n                      max-width: calc(100vw - 45px) !important;\n                    }\n                  }\n                  .author-details-img {\n                    margin-right: 10px;\n                    max-height: 250px;\n                    min-height: 150px;\n                    max-width: 250px;\n                    min-width: 150px;\n                    width: 100%;\n                    height: 100%;\n                    object-fit: contain;\n                  }\n                  .author-details-img-container {\n                    text-align: center;\n                  }\n                  .author-details-col {\n                    padding-left: 25px;\n                  }\n                '
              ),
              React__default['default'].createElement(
                'div',
                { className: 'left-wrap' },
                !isVideoSeries && showPublished && React__default['default'].createElement(
                  'div',
                  null,
                  moment.moment(published).format('LL')
                )
                /* Show Published date */
                ,
                React__default['default'].createElement(
                  'div',
                  { className: 'mb-3' },
                  !isVideoSeries && authorDetails && authorDetails.map(function (authorDetail, index) {
                    return React__default['default'].createElement(
                      'span',
                      { key: index },
                      getSerializers.renderAuthor(authorDetail.displayName, authorDetail.url, index, authorDetails.length, authorPrefix, authorDetail.biography && renderAuthorBiography(authorDetail.biography[0]), authorDetail.profileImage && urlFor({ client: props.client, source: authorDetail.profileImage, imageHeight: authorImgHeight }))
                    );
                  }),
                  React__default['default'].createElement(
                    'div',
                    null,
                    source && React__default['default'].createElement(
                      'p',
                      {
                        style: {
                          display: 'inline-block',
                          padding: '0 .25rem',
                          color: 'var(--franchise-primary, #484848)',
                          borderRadius: '2px',
                          fontWeight: 'bold',
                          border: '2px solid var(--franchise-primary, #484848)'
                        },
                        className: 'source-label' },
                      source
                    )
                  ),
                  issue && React__default['default'].createElement(
                    'div',
                    { className: 'volume-issue' },
                    issue.publication && issue.publication.name && React__default['default'].createElement(
                      'span',
                      { className: 'mb-0' },
                      React__default['default'].createElement(
                        'b',
                        null,
                        issue.publication.name
                      ),
                      ',',
                      ' '
                    ),
                    issue.name && React__default['default'].createElement(
                      'span',
                      { className: 'mb-0' },
                      issue.name,
                      ', '
                    ),
                    issue.volume && React__default['default'].createElement(
                      'span',
                      null,
                      'Volume ' + issue.volume,
                      ','
                    ),
                    issue.issueNumber && React__default['default'].createElement(
                      'span',
                      null,
                      ' Issue ' + issue.issueNumber
                    )
                  ),
                  pageNumber && React__default['default'].createElement(
                    'div',
                    { className: 'article-pageNumber' },
                    'Pages: ' + pageNumber
                  )
                ),
                !isVideoSeries && showSocialShare && React__default['default'].createElement(
                  'p',
                  null,
                  React__default['default'].createElement(SocialShare, {
                    shareUrl: shareUrl,
                    shareTitle: shareTitle,
                    shareVia: shareVia,
                    shareSummary: shareSummary,
                    shareSubject: shareSubject,
                    shareImage: shareImage,
                    size: 32,
                    siteName: siteName,
                    twitterSiteName: twitterSiteName,
                    disableMeta: true,
                    hidePinterest: hidePinterestShare,
                    hideFacebook: hideFBShare
                  })
                )
              ),
              React__default['default'].createElement(
                'div',
                null,
                React__default['default'].createElement(DocumentGroup, { article: props.article, client: props.client })
              )
            ),
            !isVideoSeries && summary && display_summary && React__default['default'].createElement(
              'p',
              null,
              React__default['default'].createElement(
                'em',
                null,
                summary
              )
            ),
            React__default['default'].createElement(
              'div',
              { className: 'ad-box', style: { textAlign: 'center' } },
              main.main_43 && !sponsoredFlag && props.article.Ads && props.article.Ads.length > 0 && props.article.Ads.map(function (ad, index) {
                if (index === 0) {
                  return React__default['default'].createElement(
                    'div',
                    {
                      key: index,
                      id: 'addid-' + index,
                      style: {
                        display: 'flex',
                        flex: '1 0 auto',
                        justifyContent: 'center',
                        alignItems: 'center',
                        textAlign: 'center'
                      } },
                    ad.component
                  );
                }
              })
            ),
            React__default['default'].createElement(
              'div',
              { className: 'block-content mt-3' },
              !isVideoSeries && renderBlockContent(article, meta),
              React__default['default'].createElement('div', { className: 'clearfix' }),
              React__default['default'].createElement(
                'noscript',
                null,
                React__default['default'].createElement(
                  'div',
                  { style: { display: 'flex', justifyContent: 'center' }, className: 'series-links' },
                  props.article.seriesDetail && props.article.seriesDetail.prevUrl && React__default['default'].createElement(
                    'a',
                    { className: 'mx-3', href: props.article.seriesDetail.prevUrl },
                    'Previous ',
                    props.article.seriesDetail.type
                  ),
                  props.article.seriesDetail && props.article.seriesDetail.nextUrl && React__default['default'].createElement(
                    'a',
                    { className: 'mx-3', href: props.article.seriesDetail.nextUrl },
                    'Next ',
                    props.article.seriesDetail.type
                  )
                )
              ),
              issue && issue.url && React__default['default'].createElement(
                'a',
                { rel: 'noopener', href: issue.url, target: '_blank', title: 'Download issue' },
                React__default['default'].createElement('img', { style: { margin: '1rem', maxHeight: '40px', maxWidth: '40px' }, src: '/download.png', alt: 'download issue' }),
                'Download Issue : ',
                issue.name
              )
            ),
            React__default['default'].createElement('div', { className: 'clearfix', style: { minHeight: '1px' } }),
            article.documentGroup && article.documentGroup.isSeries && props.sliderData && !seriesInfo.hasVideo && React__default['default'].createElement(
              'div',
              null,
              false ,
              React__default['default'].createElement(SeriesSlider.SeriesSlider, { dataset: props.sliderData, client: client, nowPlaying: article.title, displayEpisodeNumber: true })
            ),
            showRelatedArticles && !showIsi && React__default['default'].createElement(RelatedContent, null),
            disqusConfig && showDisqus && React__default['default'].createElement(
              'div',
              { id: 'disqusContainer' },
              React__default['default'].createElement(disqusReact.DiscussionEmbed, {
                shortname: disqusConfig.shortname,
                config: {
                  url: disqusConfig.url,
                  identifier: disqusConfig.identifier,
                  title: disqusConfig.title
                }
              })
            )
          ),
          renderIsiContent(props.article)
        )
      ),
      showIsi && Array.isArray(isi) && isi.length > 0 && React__default['default'].createElement(
        ISI,
        null,
        React__default['default'].createElement(BlockContent.BlockContent, {
          serializers: getSerializers.getSerializers(client, pageview, videoAccountIDs, onVote, true, drupalLeadSettings, currentPage, false, false, null, props.article.Ads, targeting),
          blocks: isi
        })
      ),
      main.main_43 && !sponsoredFlag && props.article.Ads && props.article.Ads.length > 0 && props.article.Ads.map(function (ad, index) {
        if (index > 0) {
          return React__default['default'].createElement(
            'div',
            { key: index, id: 'addid-' + index, style: { display: 'flex', flex: '1 0 auto' } },
            ad.component
          );
        }
      }),
      React__default['default'].createElement(
        'noscript',
        null,
        props.infiniteScroll && props.article.relatedArticle && props.article.relatedArticle[0] && props.article.relatedArticle[0].url && props.article.relatedArticle[0].url.current && React__default['default'].createElement(
          'div',
          { style: { textAlign: 'center' } },
          React__default['default'].createElement(
            'a',
            { href: '/view/' + props.article.relatedArticle[0].url.current },
            'Related Article ',
            '>>>'
          )
        )
      ),
      props.infiniteScroll && React__default['default'].createElement('hr', { className: 'article-seperater mb-5 mt-3' })
    );
  };

  if (passwordLock) {
    if (auth === 2) {
      return detail();
    } else {
      return form();
    }
  } else {
    return detail();
  }
});

var _this$1 = undefined;

var ArticleQueue = function ArticleQueue(props) {
  var _props$prevUrl = props.prevUrl,
      prevUrl = _props$prevUrl === undefined ? '/' : _props$prevUrl,
      Ads = props.Ads,
      _props$maxListLength = props.maxListLength,
      maxListLength = _props$maxListLength === undefined ? 10 : _props$maxListLength;
      props.sponsoredTaxonomies;
      var _props$cpModification = props.cpModificationRequired,
      cpModificationRequired = _props$cpModification === undefined ? false : _props$cpModification,
      _props$authorPrefix = props.authorPrefix,
      authorPrefix = _props$authorPrefix === undefined ? 'authors' : _props$authorPrefix,
      showRelatedArticles = props.showRelatedArticles,
      canonicalTag = props.canonicalTag;

  var _useState = React.useState(0),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      containerHeight = _useState2[0],
      setContainerHeight = _useState2[1];

  React.useEffect(function () {
    setContainerHeight(function () {
      return window.innerHeight;
    });
    var handleResize = function handleResize() {
      return setContainerHeight(function () {
        return window.innerHeight;
      });
    };
    window.addEventListener('resize', handleResize);
    return function () {
      return window.removeEventListener('resize', handleResize);
    };
  }, []);

  var firstArticle = function firstArticle() {
    var article = _extends._Object$assign({}, props.article);
    var targeting = getTargeting.getTargeting(props);
    article.Ads = Ads.getRightItems(targeting);
    return article;
  };

  var _useState3 = React.useState([firstArticle()]),
      _useState4 = slicedToArray._slicedToArray(_useState3, 2),
      queueData = _useState4[0],
      setQueueData = _useState4[1];

  var _useState5 = React.useState(queueData[0]._id),
      _useState6 = slicedToArray._slicedToArray(_useState5, 2),
      active = _useState6[0],
      setActive = _useState6[1];

  var refreshAD = function refreshAD(path) {
    var activeArticle = queueData.find(function (item) {
      return item.url.current === path;
    });
    var targeting = getTargeting.getTargeting({ article: activeArticle, cpModificationRequired: cpModificationRequired, position: props.position, prevUrl: prevUrl });
    if (!main.main_43) {
      index.lib_3.getGoogletag().then(function (googletag) {
        if (window.googletag && googletag.pubadsReady) {
          var slots = googletag.pubads().getSlots();
          slots.forEach(function (slot) {
            var pos = slot.getTargeting('pos');
            slot.clearTargeting();
            keys._Object$keys(targeting).forEach(function (key) {
              slot.setTargeting(key, targeting[key]);
            });
            slot.setTargeting('pos', pos);
          });
          index.lib_3.refresh();
        }
      });
    }
    //Refresh leaderboard ad on mobile
    if (main.main_43) {
      var leaderboardSlotId = '';
      index.lib_3.getGoogletag().then(function (googletag) {
        if (window.googletag && googletag.pubadsReady) {
          var slots = googletag.pubads().getSlots();
          slots.forEach(function (slot) {
            var pos = slot.getTargeting('pos');
            if (pos == 'top-mobile') {
              //gets the slotId of the leaderboard ad to refresh
              leaderboardSlotId = slot.getSlotId().getDomId();
              slot.clearTargeting();
              keys._Object$keys(targeting).forEach(function (key) {
                slot.setTargeting(key, targeting[key]);
              });
              slot.setTargeting('pos', pos);
            }
          });
          index.lib_3.refresh(leaderboardSlotId);
        }
      });
    }
  };

  var hasVerticalScroll = function hasVerticalScroll() {
    if (window.innerHeight) {
      return document.body.offsetHeight > window.innerHeight;
    } else {
      return document.documentElement.scrollHeight > document.documentElement.offsetHeight || document.body.scrollHeight > document.body.offsetHeight;
    }
  };

  React.useEffect(function () {
    // Fetching related article after component mounted if vertical scroll not found
    setTimeout(function () {
      if (!hasVerticalScroll()) {
        loadmore();
      }
    }, 1000);
  }, [queueData.length]);

  var loadmore = function () {
    var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee() {
      var index, article, startingIndex, endingIndex, targeting;
      return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              if (!(queueData && queueData.length < maxListLength)) {
                _context.next = 27;
                break;
              }

              index = queueData.length - 1;
              article = null;
              _context.prev = 3;
              _context.next = 6;
              return getRelatedArticle(null, props.client, props.article, prevUrl, index);

            case 6:
              article = _context.sent;
              _context.next = 12;
              break;

            case 9:
              _context.prev = 9;
              _context.t0 = _context['catch'](3);

              console.error(_context.t0);

            case 12:
              if (!(article && article._id)) {
                _context.next = 27;
                break;
              }

              //query next 4 related article without repeating previous 4 related articles
              startingIndex = queueData.length + 1;
              endingIndex = startingIndex + 2;
              _context.prev = 15;
              _context.next = 18;
              return getRelatedArticle(null, props.client, props.article, prevUrl, startingIndex + '..' + endingIndex);

            case 18:
              article.relatedArticle = _context.sent;
              _context.next = 24;
              break;

            case 21:
              _context.prev = 21;
              _context.t1 = _context['catch'](15);

              console.error(_context.t1);

            case 24:
              targeting = getTargeting.getTargeting({ article: article, cpModificationRequired: cpModificationRequired, prevUrl: prevUrl });

              article.Ads = Ads.getRightItems(targeting);
              setQueueData([].concat(toConsumableArray._toConsumableArray(queueData), [article]));

            case 27:
            case 'end':
              return _context.stop();
          }
        }
      }, _callee, _this$1, [[3, 9], [15, 21]]);
    }));

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

  var changeMeta = function changeMeta(meta) {
    document.title = meta.shareTitle;
    //this was throwing an error if there was no description, doing a check for the description meta
    if (document.querySelector('meta[name="description"]')) document.querySelector('meta[name="description"]').setAttribute('content', meta.shareSummary);
    document.querySelector('meta[name="keywords"]').setAttribute('content', meta.shareKeywords);
    document.querySelector('meta[property="og:url"]').setAttribute('content', meta.shareUrl);
    document.querySelector('meta[property="og:title"]').setAttribute('content', meta.shareTitle);
    document.querySelector('meta[property="og:site_name"]').setAttribute('content', meta.shareVia);
    document.querySelector('meta[property="og:description"]').setAttribute('content', meta.shareSummary);
    document.querySelector('meta[name="twitter:title"]').setAttribute('content', meta.shareTitle);
    document.querySelector('meta[name="twitter:image"]').setAttribute('content', meta.shareImage);
    document.querySelector('meta[name="twitter:site"]').setAttribute('content', meta.shareVia);
    //this was throwing an error if there was no description, doing a check for the description meta
    if (document.querySelector('meta[name="twitter:description"]')) document.querySelector('meta[name="twitter:description"]').setAttribute('content', meta.shareSummary);
    if (canonicalTag) {
      document.querySelector('link[rel="canonical"]').setAttribute('href', meta.shareUrl);
    }
  };

  var onChangeArticle = function onChangeArticle(path, meta) {
    var newPath = '/view/' + path;
    var activeArticle = queueData.find(function (item) {
      return item.url.current === path;
    });
    setActive(function () {
      return activeArticle._id;
    });
    // Change URL and do other changes
    window.history.pushState({ page: path }, meta.shareTitle, newPath);
    changeMeta(meta);
    if (props.setCustomDimensions) {
      props.setCustomDimensions(activeArticle, '200', prevUrl);
    }
    if (props.pageview) props.pageview(newPath);
    refreshAD(path);
  };

  return React__default['default'].createElement(
    index_es.InfiniteScroll,
    { dataLength: queueData.length, next: loadmore, scrollThreshold: '40%', hasMore: true, style: { overflow: 'hidden' } },
    queueData.map(function (article, index) {
      return React__default['default'].createElement(
        React__default['default'].Fragment,
        null,
        React__default['default'].createElement(Article, _extends._extends({
          key: index
        }, props, {
          containerHeight: containerHeight,
          onChangeArticle: onChangeArticle,
          authorPrfix: authorPrefix,
          article: article,
          cpModificationRequired: cpModificationRequired,
          active: active === article._id
          // Passing queueData to check for single article
          , queueData: queueData,
          showRelatedArticles: showRelatedArticles
        }))
      );
    })
  );
};

var _this = undefined;

var View = function View(props) {
  var router = Router.useRouter();
  var shareOptions = props.shareOptions,
      article = props.article,
      _props$article = props.article,
      hideComments = _props$article.hideComments,
      content_placement = _props$article.content_placement,
      _props$sponsoredFlag = props.sponsoredFlag,
      sponsoredFlag = _props$sponsoredFlag === undefined ? false : _props$sponsoredFlag;
      props.sponsoredTaxonomies;
      var Ads = props.Ads,
      setCustomDimensions = props.setCustomDimensions,
      statusCode = props.statusCode,
      prevUrl = props.prevUrl,
      pageview = props.pageview,
      _props$showRelatedArt = props.showRelatedArticles,
      showRelatedArticles = _props$showRelatedArt === undefined ? false : _props$showRelatedArt,
      _props$canonicalTag = props.canonicalTag,
      canonicalTag = _props$canonicalTag === undefined ? true : _props$canonicalTag,
      _props$infiniteScroll = props.infiniteScrollFlag,
      infiniteScrollFlag = _props$infiniteScroll === undefined ? true : _props$infiniteScroll;
  var _props$article2 = props.article,
      _props$article2$passw = _props$article2.passwordLock,
      passwordLock = _props$article2$passw === undefined ? false : _props$article2$passw;
      _props$article2.description;
      var title = _props$article2.title,
      seriesShareOptions = _props$article2.seriesShareOptions;

  var _useState = React.useState(0),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      currentPage = _useState2[0],
      setCurrentPage = _useState2[1];
  // Logging GA pageview for the initial article with custom dimensions


  React.useEffect(function () {
    if (pageview && setCustomDimensions) {
      var timer = void 0;
      var waitAndExicute = function waitAndExicute() {
        if (typeof window.GA_INITIALIZED !== 'undefined') {
          setCustomDimensions(article, statusCode, prevUrl);
          pageview(router.asPath);
        } else timer = setTimeout(waitAndExicute, 1000);
      };
      waitAndExicute();
      return function () {
        clearTimeout(timer);
      };
    }
  }, []);

  // disable infinite scroll
  var checkVideoSeries = function checkVideoSeries(article) {
    if (!article || !article.body) {
      return false;
    }
    for (var i = 0; i < article.body.length; i++) {
      var row = article.body[i];
      if (typeof row.videos !== 'undefined') {
        return true;
      }
    }
    return false;
  };

  var checkArticleSeries = function checkArticleSeries(article) {
    if (!article || !article.body) {
      return false;
    }
    for (var i = 0; i < article.body.length; i++) {
      if (article.body[i]._type === 'articleSeries') {
        return true;
      }
    }
    return false;
  };

  var isVideoSeries = checkVideoSeries(props.article);
  var isArticleSeries = checkArticleSeries(props.article);
  var commentsEnabledInTaxonomy = Array.isArray(content_placement) && content_placement.some(function (t) {
    return t.showComments === true;
  });
  var showDisqus = commentsEnabledInTaxonomy || hideComments === false;
  var needInfiniteScroll = ['Articles', 'Videos', 'Podcasts'].includes(article.category.name) && article.taxonomyMapping && article.passwordLock !== true && !isVideoSeries && !isArticleSeries && !article.ExcludeFromInfiniteScroll && !sponsoredFlag && infiniteScrollFlag && !article.showIsi && (!article.documentGroup || !article.documentGroup.isSeries) && !showDisqus;

  if (['Articles', 'Videos', 'Podcasts'].includes(article.category.name)) {
    title = null;
  }

  if (!needInfiniteScroll && !title) {
    title = props.article ? props.article.title : '';
  }
  // add mobile ads to articles not using infinite scroll
  if (!needInfiniteScroll) {
    var targeting = getTargeting.getTargeting(props);
    article.Ads = Ads.getRightItems(targeting);
    if (!sponsoredFlag && Ads.getVideoContextualAD) {
      article.contextualVideoAD = Ads.getVideoContextualAD(getTargeting.getTargeting(props, 'in-context_video'));
    }
    if (!sponsoredFlag && Ads.getNativeContextualAD) {
      article.contextualAD = Ads.getNativeContextualAD(getTargeting.getTargeting(props, 'native-ad'));
    }
  }
  React.useEffect(function () {
    router.asPath && router.asPath.length > 0 && router.asPath.includes('?') && router.asPath.split('?')[1].split('&').forEach(function (item) {
      if (item.includes('page=')) {
        setCurrentPage(item.split('=')[1]);
      } else {
        setCurrentPage(0);
      }
    });
    if (!router.asPath.includes('page=') && currentPage !== 0) {
      setCurrentPage(0);
    }
  }, [router]);

  var meta_description = seriesShareOptions && seriesShareOptions.seriesSummary ? '' + seriesShareOptions.seriesSummary + (currentPage > 0 ? ' | Page ' + currentPage : '') : article.seo && article.seo.meta_description ? '' + article.seo.meta_description + (currentPage > 0 ? ' | Page ' + currentPage : '') : shareOptions.shareSummary ? '' + shareOptions.shareSummary + (currentPage > 0 ? ' | Page ' + currentPage : '') : '' + (currentPage > 0 ? 'Page ' + currentPage : '');

  if (isVideoSeries) {
    meta_description = seriesShareOptions && seriesShareOptions.seriesSummary ? '' + seriesShareOptions.seriesSummary + (currentPage > 0 ? ' | Page ' + currentPage : '') : '';
  }

  return React__default['default'].createElement(
    React__default['default'].Fragment,
    null,
    React__default['default'].createElement(
      Head__default['default'],
      null,
      React__default['default'].createElement(
        'title',
        { key: 'title' },
        seriesShareOptions && seriesShareOptions.seriesTitle ? '' + seriesShareOptions.seriesTitle + (currentPage > 0 ? ' | Page ' + currentPage : '') : article && article.seo && article.seo.seo_title ? '' + article.seo.seo_title + (currentPage > 0 ? ' | Page ' + currentPage : '') : '' + article.title + (currentPage > 0 ? ' | Page ' + currentPage : '')
      ),
      meta_description && React__default['default'].createElement('meta', { name: 'description', key: 'description', content: meta_description }),
      React__default['default'].createElement('meta', { name: 'keywords', content: getKeywords(article).join(','), key: 'keywords' }),
      passwordLock && React__default['default'].createElement('meta', { name: 'robots', content: 'noindex, nofollow' }),
      React__default['default'].createElement('meta', {
        property: 'og:url',
        content: seriesShareOptions && seriesShareOptions.seriesUrl ? shareOptions.shareUrl + seriesShareOptions.seriesUrl : shareOptions.shareUrl,
        key: 'og:url'
      }),
      React__default['default'].createElement('meta', {
        property: 'og:title',
        content: seriesShareOptions && seriesShareOptions.seriesTitle ? '' + seriesShareOptions.seriesTitle + (currentPage > 0 ? ' | Page ' + currentPage : '') : article.seo && article.seo.seo_title ? '' + article.seo.seo_title + (currentPage > 0 ? ' | Page ' + currentPage : '') : '' + shareOptions.shareTitle + (currentPage > 0 ? ' | Page ' + currentPage : ''),
        key: 'og:title'
      }),
      React__default['default'].createElement('meta', {
        property: 'og:image',
        content: seriesShareOptions && seriesShareOptions.seriesThumbnail ? seriesShareOptions.seriesThumbnail : shareOptions.shareImage,
        key: 'og:image'
      }),
      React__default['default'].createElement('meta', { property: 'og:site_name', content: props.Settings.title, key: 'og:site_name' }),
      React__default['default'].createElement('meta', { property: 'og:description', content: meta_description, key: 'og:description' }),
      React__default['default'].createElement('meta', { name: 'twitter:card', content: 'summary', key: 'twitter:card' }),
      React__default['default'].createElement('meta', {
        name: 'twitter:title',
        content: seriesShareOptions && seriesShareOptions.seriesTitle ? '' + seriesShareOptions.seriesTitle + (currentPage > 0 ? ' | Page ' + currentPage : '') : article.seo && article.seo.seo_title ? '' + article.seo.seo_title + (currentPage > 0 ? ' | Page ' + currentPage : '') : '' + shareOptions.shareTitle + (currentPage > 0 ? ' | Page ' + currentPage : ''),
        key: 'twitter:title'
      }),
      React__default['default'].createElement('meta', {
        name: 'twitter:image',
        content: seriesShareOptions && seriesShareOptions.seriesThumbnail ? seriesShareOptions.seriesThumbnail : shareOptions.shareImage,
        key: 'twitter:image'
      }),
      React__default['default'].createElement('meta', { name: 'twitter:site', content: '@' + props.Settings.title, key: 'twitter:site' }),
      React__default['default'].createElement('meta', { name: 'twitter:description', content: meta_description, key: 'twitter:description' }),
      canonicalTag && React__default['default'].createElement('link', {
        rel: 'canonical',
        href: seriesShareOptions && seriesShareOptions.seriesUrl ? shareOptions.shareUrl + seriesShareOptions.seriesUrl : shareOptions.shareUrl,
        key: 'canonical'
      }),
      React__default['default'].createElement(
        'noscript',
        null,
        props.article.seriesDetail && props.article.seriesDetail.prevUrl && React__default['default'].createElement('link', { rel: 'prev', href: props.article.seriesDetail.prevUrl }),
        props.article.seriesDetail && props.article.seriesDetail.nextUrl && React__default['default'].createElement('link', { rel: 'next', href: props.article.seriesDetail.nextUrl })
      )
    ),
    !needInfiniteScroll ? React__default['default'].createElement(Article, _extends._extends({ infiniteScroll: false, showRelatedArticles: showRelatedArticles, showDisqus: showDisqus }, props)) : React__default['default'].createElement(ArticleQueue, _extends._extends({
      infiniteScroll: true,
      showRelatedArticles: showRelatedArticles,
      canonicalTag: canonicalTag,
      checkSponsered: true,
      Ads: props.WAds,
      onVote: function onVote() {},
      sponsoredTaxonomies: []
    }, props))
  );
};

//This should be called in /view/[url] getInitialProps to fetch the article data and related articles.  This will also set the sponsoredFlag to true if any taxonomies have disabled ads.
View.returnGetInitialProps = function () {
  var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee(url, prevUrl, seriesVid, client, sao) {
    var context = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;

    var article, relatedArticleQuery, sliderData, statusCode, sliderArticles, _context$query$series, seriesArticle, sponsoredFlag;

    return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return client.fetch(getQuery('article'), { url: url });

          case 2:
            article = _context.sent;
            relatedArticleQuery = getQuery('related');

            article.seriesDetail = getSeriesDetail(article, seriesVid);
            sliderData = [];
            statusCode = 200;

            if (!article || !article._id || !article.body) {
              statusCode = 404;
            }

            if (!(article.documentGroup && article.documentGroup.isSeries)) {
              _context.next = 13;
              break;
            }

            _context.next = 11;
            return client.fetch('*[!(_id in path("drafts.**")) \n    && _type == "article"\n    && defined(title)\n    && references(\'' + article.documentGroup._id + '\')\n    && is_visible == true\n    && defined(published)\n    && dateTime(published) <= dateTime(now())\n  ] | order(published asc)  {\n      title,\n      thumbnail,\n      url,\n      published\n    }');

          case 11:
            sliderArticles = _context.sent;

            sliderData = sliderArticles;

          case 13:
            _context$query$series = context.query.seriesArticle, seriesArticle = _context$query$series === undefined ? false : _context$query$series;

            if ((seriesArticle || seriesVid) && article.body) {
              article.body.map(function (block) {
                if (block._type === 'articleSeries' && block.articles && block.articles.length > 0) {
                  block.articles.map(function (subArticle) {
                    if (subArticle.param.current === seriesArticle) {
                      var seriesShareOptions = {
                        seriesUrl: '?seriesArticle=' + seriesArticle,
                        seriesTitle: subArticle.title,
                        seriesSummary: subArticle.summary,
                        seriesThumbnail: subArticle.thumbnail && subArticle.thumbnail.asset ? urlFor({ client: client, source: subArticle.thumbnail.asset }) : null
                      };
                      article.seriesShareOptions = seriesShareOptions;
                    }
                  });
                }
                if (block._type === 'youtubeGallery' && block.videos && block.videos.length > 0) {
                  block.videos.map(function (video, index) {
                    if (index + 1 === Number(seriesVid)) {
                      var seriesShareOptions = {
                        seriesUrl: '?seriesVid=' + seriesVid,
                        seriesTitle: video.title,
                        seriesSummary: video.intro,
                        seriesThumbnail: video.thumbnail && video.thumbnail.asset ? urlFor({ client: client, source: video.thumbnail.asset }) : null
                      };
                      article.seriesShareOptions = seriesShareOptions;
                    }
                  });
                }
              });
            }
            sponsoredFlag = false;
            //check for disableAds flag on each taxonomoy

            if (article && article.content_placement) {
              article.content_placement.forEach(function (x) {
                if (x.disableAds) {
                  sponsoredFlag = true;
                }
              });
            }
            //check for disableAds flag on content category
            if (article.category && article.category.disableAds) {
              sponsoredFlag = true;
            }

            if (!article.disableRelatedContent) {
              _context.next = 23;
              break;
            }

            article.relatedArticle = null;
            _context.next = 27;
            break;

          case 23:
            if (!article) {
              _context.next = 27;
              break;
            }

            _context.next = 26;
            return getRelatedArticle(context, client, article, prevUrl, '0..2');

          case 26:
            article.relatedArticle = _context.sent;

          case 27:
            return _context.abrupt('return', {
              url: url,
              sao: sao,
              statusCode: statusCode,
              prevUrl: prevUrl,
              relatedArticleQuery: relatedArticleQuery,
              article: article,
              sliderData: sliderData,
              sponsoredFlag: sponsoredFlag
            });

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

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

module.exports = View;
