'use strict';

var slicedToArray = require('./slicedToArray-067dd3bc.js');
var toConsumableArray = require('./toConsumableArray-d7797c2b.js');
var _extends = require('./extends-be0d85bc.js');
var React = require('react');
var reactBootstrap = require('react-bootstrap');
var urlFor = require('./urlFor.js');
var index_es = require('./index.es-1ab8dda7.js');
var moment = require('./moment-aca40de1.js');
var visibilitySensor = require('./visibility-sensor-56020df6.js');
var index$1 = require('./index-d2a6ef75.js');
var Router = require('next/router');
var index = require('./index-65621b6c.js');
var main = require('./main-ae8472f3.js');
var entities = require('./entities-df1aed86.js');
var ADInfeed = require('./ADInfeed-89f63b7d.js');
var AuthorComponent = require('./AuthorComponent-7d00f6d5.js');
var lodash = require('./lodash-f0783643.js');
var ADlgInfeed = require('./ADlgInfeed-a536168e.js');
var getContentCategory = require('./getContentCategory-f38a4c00.js');
var timeDifferenceCalc = require('./timeDifferenceCalc.js');
require('./_commonjsHelpers-06173234.js');
require('./web.dom.iterable-d98303e0.js');
require('./core.get-iterator-method-5643aa10.js');
require('./_iter-detect-b1df62f0.js');
require('./index-d48b231c.js');
require('react-dom');
require('./events-1b438fe7.js');
require('prop-types');
require('react-bootstrap/Card');
require('./AdSlot.js');
require('./debounce-d4a2369b.js');
require('./isSymbol-03abbdf0.js');
require('./toNumber-5e1fac58.js');
require('./Beam.js');
require('./stringify-f7a37a8d.js');
require('./asyncToGenerator-65df6bf8.js');
require('./_library-dd23b178.js');
require('./_set-species-0c7864a2.js');
require('./Segment.js');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var renderCardImage = function renderCardImage(row, client) {
  var imageHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  var imageWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  var imageMaxHeight = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
  var imageFit = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;

  var url = urlFor({ client: client, source: row.thumbnail, imageHeight: imageHeight, imageWidth: imageWidth, imageMaxHeight: imageMaxHeight, imageFit: imageFit });

  return url;
};

var loadMore = function loadMore(values, setValues, itemsPerPage) {
  console.log('Values:::', values);
  setValues({
    page: values.page + 1,
    from: values.from + itemsPerPage,
    to: values.to + itemsPerPage
  });
};

var loadData = function loadData(values, query, client, params, setData, setScrolling, setLastDataSize, pointer, pointerArray) {
  params = _extends._extends({}, params, {
    from: values.from,
    to: values.to
  });
  client.fetch(query, params).then(function (dataArr) {
    if (pointer && pointerArray) {
      dataArr = dataArr[pointerArray][pointer];
    }

    if (!dataArr) {
      dataArr = [];
    }

    dataArr = dataArr.map(function (item) {
      return _extends._extends({}, item, {
        pageNumber: values.page
      });
    });

    if (dataArr.length > 0) {
      setData(function (prevData) {
        return [].concat(toConsumableArray._toConsumableArray(prevData), toConsumableArray._toConsumableArray(dataArr));
      });
      setLastDataSize(dataArr.length);
      setScrolling(true);
    } else {
      setLastDataSize(0);
      setScrolling(false);
    }
  });
};

var changePageNumber = function changePageNumber(pageNumber, seoPaginate, pageview, router, currentPage, setCurrentPage, itemsPerPage, itemIndex) {
  if (seoPaginate) {
    var path = router.asPath;
    var qrIndex = path.indexOf('?');
    var pathname = router.pathname;
    var queryString = '';

    if (qrIndex > 0) {
      path = path.substring(1, qrIndex);

      var partialQS = router.asPath.substring(qrIndex + 1);
      var partialQSArr = partialQS.split('&');

      // exclude page=xxx from query string
      partialQSArr.map(function (item) {
        var itemArr = item.split('=');
        var key = itemArr[0];
        var val = itemArr[1];

        if (key !== 'page') {
          queryString += (queryString.length === 0 ? '' : '&') + key + '=' + val;
        }
      });
    }

    if (queryString.length > 0) {
      path += '?' + queryString;
    }

    pageNumber = parseInt(pageNumber);
    // const index = Number(itemIndex)
    // const perPage = Number(itemsPerPage)

    // pageNumber = Math.ceil((index + 1) / perPage)

    if (currentPage !== pageNumber) {
      index$1.lib_3.refresh();

      setCurrentPage(pageNumber);
      if (path[0] !== '/') {
        path = '/' + path;
      }

      var newPath = pageNumber === 1 ? '' + path : '' + path + (queryString.length > 0 ? '&' : '?') + 'page=' + pageNumber;

      // if (pageview) {
      //   pageview(newPath)
      // }

      router.push(pathname, newPath, {
        shallow: true
      });
    }
  }
};

var checkExternalUrl = function checkExternalUrl(url) {
  return new RegExp(['http', 'https'].join('|')).test(url);
};

var cardLoader = function cardLoader(data, client, mapping, values, seoPaginate, pageview, router, currentPage, setCurrentPage, showPublished, defaultImage, showAuthor, showCategory, imageHeight, imageWidth, imageMaxHeight, imageFit, rightItems, brandInsightAd, showBI, itemsPerPage, heroContent, lgInfeedAd, showPubInfo, contentCategoryMapping, showTimeDiff, showTaxonomies, showIntro) {
  var numberOfItemsBeforeAd = data.length < 6 ? data.length : 6;
  var insertBrandInsightAd = function insertBrandInsightAd(arr, index, newElement) {
    return [].concat(toConsumableArray._toConsumableArray(arr.slice(0, index)), [newElement], toConsumableArray._toConsumableArray(arr.slice(index)));
  };

  var _useState = React.useState(!showBI || !brandInsightAd ? true : false),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      dataRemapped = _useState2[0],
      setDataRemapped = _useState2[1];
  //  Need to pass flag "lgInfeedAd={true}" along with brandInsightAd from site level for large infeed-ad to render
  //  Checking window and lgInfeedAd flag in desktop view ( window >= 1400px ).


  if (lgInfeedAd && brandInsightAd && typeof window !== 'undefined' && window.innerWidth >= 1400) {
    var lgInfeed = {
      _type: 'lg-infeed',
      adUnit: brandInsightAd.adUnit,
      className: 'lg-infeed',
      networkID: brandInsightAd.networkID,
      sizes: [728, 90],
      //  Adding sizeMapping for showing ad above 1400px
      sizeMapping: [{
        viewport: [1400, 0],
        sizes: [[728, 90]]
      }, { viewport: [0, 0], sizes: [] }],
      targeting: {
        content_placement: brandInsightAd.targeting.content_placement,
        document_url: brandInsightAd.targeting.document_url,
        document_group: brandInsightAd.targeting.document_group,
        rootDocumentGroup: brandInsightAd.targeting.rootDocumentGroup
      },
      /* Passing refresh flag */
      refreshFlag: brandInsightAd.refreshFlag ? brandInsightAd.refreshFlag : false
    };

    var chunks = lodash.lodash.chunk(data, 6).map(function (chunk) {
      var set = lodash.lodash.chunk(chunk, 2);
      for (var i = 0; i < set.length; i++) {
        if (i !== set.length - 1) {
          set[i].push(lgInfeed);
        }
      }
      return lodash.lodash.flattenDeep(set);
    });
    data = lodash.lodash.flatten(chunks);
    !dataRemapped && setDataRemapped(true); // To detect if appending of insights ads are completed
  }

  // set dataRemap to true as there are no infeed or BI ads or window width is less than limit
  React.useEffect(function () {
    if (typeof window !== 'undefined' && (!lgInfeedAd || !brandInsightAd || window.innerWidth < 1400) && !dataRemapped) {
      setDataRemapped(true);
    }
  }, []);

  if (showBI && brandInsightAd) {
    //  Checking window and lgInfeedAd flag in desktop view ( window >= 1400px ).
    if (lgInfeedAd && typeof window !== 'undefined' && window.innerWidth >= 1400) brandInsightAd.interval = 8;
    var pos = 0;
    for (var i = 1; pos < data.length; i++) {
      var inFeedAd = {
        adUnit: brandInsightAd.adUnit,
        className: brandInsightAd.className,
        networkID: brandInsightAd.networkID,
        sizes: brandInsightAd.sizes,
        slotId: brandInsightAd.slotId + '_' + i,
        targeting: {
          pos: 'infeed',
          content_placement: brandInsightAd.targeting.content_placement,
          document_url: brandInsightAd.targeting.document_url,
          document_group: brandInsightAd.targeting.document_group,
          rootDocumentGroup: brandInsightAd.targeting.rootDocumentGroup
        },
        _type: 'brandInsightAd',
        /* Passing refresh flag */
        refreshFlag: brandInsightAd.refreshFlag ? brandInsightAd.refreshFlag : false
      };

      data = insertBrandInsightAd(data, pos, inFeedAd);
      pos += brandInsightAd.interval + 1;
    }
  }

  // 'articleCount' is New parameter to use instead of 'index' while passing to 'changePageNumber()'
  // 'index' was including the indexes for infeed ads along with article count making the page number change before it reaches last article.
  // 'articleCount' will be the indexes of only the articles in the deck.
  var articleCount = -1;
  data = data.map(function (ele, i) {
    if (ele._type === 'lg-infeed') {
      //  Setting pos as top2 for the first occurence of large infeed ad
      // const pos = data.indexOf(data.find((d) => d._type === 'lg-infeed')) === i ? 'top2' : `lg-infeed_${i}`
      return _extends._extends({}, ele, { slotId: 'lg-infeed_' + i, targeting: _extends._extends({}, ele.targeting, { pos: 'lg-infeed' }) });
    } else if (ele._type === 'article') {
      // incrementing 'articleCount' for each article.
      ++articleCount;
      return _extends._extends({}, ele, { articleCount: articleCount });
    } else {
      return ele;
    }
  });

  var featureCount = 0;
  return React__default["default"].createElement(
    'div',
    null,
    data && data.length > 0 ? dataRemapped ? // For Javascript Enabled Cases
    data.map(function (article, index$1) {
      var pageNumber = article.pageNumber || values.page;
      var contentCategoryName = article.contentCategory ? article.contentCategory.name : 'Articles';

      if (article._type === 'feature') {
        featureCount++;
        if (article.blank || checkExternalUrl(article.url.current)) {
          return React__default["default"].createElement(
            visibilitySensor.VisibilitySensor,
            {
              key: article._id ? article._id : index$1,
              partialVisibility: true,
              onChange: function onChange(isVisible) {
                isVisible && changePageNumber(pageNumber, seoPaginate, pageview, router, currentPage, setCurrentPage);
              } },
            React__default["default"].createElement(
              React__default["default"].Fragment,
              null,
              React__default["default"].createElement(
                reactBootstrap.Media,
                {
                  key: article._id ? article._id : index$1,
                  className: 'feature-media',
                  style: { flexDirection: 'column', marginBottom: '1.25rem', paddingBottom: '1.25rem', borderBottom: '1px solid #ddd' } },
                (article.thumbnail && article.thumbnail.asset || defaultImage) && React__default["default"].createElement(
                  'a',
                  { rel: 'noopener', href: article.url.current, target: '_blank', className: 'feature-wrapper' },
                  React__default["default"].createElement(
                    index.LazyLoad,
                    { height: imageHeight, placeholder: React__default["default"].createElement(ImagePlaceholder, null) },
                    article.thumbnail && article.thumbnail.asset ? React__default["default"].createElement('img', { className: 'img-fluid', src: renderCardImage(article, client, imageHeight, imageWidth, imageMaxHeight, imageFit), alt: article.title }) : article.thumbnail ? React__default["default"].createElement('img', { src: article.thumbnail, className: 'mr-3', alt: article.title }) : React__default["default"].createElement('img', { src: defaultImage, src2: article.thumbnail, className: 'mr-3', width: '240', height: '135', alt: article.title })
                  ),
                  article.source && React__default["default"].createElement(
                    'div',
                    { className: 'content-category-label' },
                    React__default["default"].createElement(
                      'div',
                      { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                      article.source
                    )
                  )
                ),
                React__default["default"].createElement(
                  reactBootstrap.Media.Body,
                  null,
                  React__default["default"].createElement(
                    'a',
                    { rel: 'noopener', href: article.url.current, target: '_blank' },
                    article.title && React__default["default"].createElement(
                      'h4',
                      { className: 'card-title', style: { fontWeight: '500', color: 'var(--gray-dark)', marginBottom: '.5rem' } },
                      article.title
                    )
                  ),
                  showPublished && !showTimeDiff && article.published && React__default["default"].createElement(
                    'p',
                    { className: 'card-text', style: { color: 'var(--dark)', margin: '.25rem 0' } },
                    moment.moment(article.published).format('MMMM DD, YYYY')
                  ),
                  showTimeDiff && article.published && React__default["default"].createElement(
                    'p',
                    { className: 'card-text', style: { color: '#464644', lineHeight: '1.25', fontSize: '.875rem', margin: '.25rem 0' } },
                    showTaxonomies && article.taxonomyMapping && article.taxonomyMapping.map(function (taxonomy, index) {
                      if (index > 3) {
                        return null;
                      }
                      if (index === 3) {
                        return React__default["default"].createElement(
                          React__default["default"].Fragment,
                          null,
                          React__default["default"].createElement(
                            'em',
                            { style: { marginRight: '.5rem' } },
                            '...'
                          )
                        );
                      }
                      return React__default["default"].createElement(
                        React__default["default"].Fragment,
                        null,
                        React__default["default"].createElement(
                          'em',
                          null,
                          taxonomy.name
                        ),
                        ' |',
                        ' '
                      );
                    }),
                    ' ',
                    React__default["default"].createElement(
                      'span',
                      { style: { display: 'inline-block' } },
                      timeDifferenceCalc(article.published)
                    )
                  ),
                  showAuthor && article.authorMapping && article.authorMapping.length > 0 && React__default["default"].createElement(
                    index.LazyLoad,
                    { height: 50 },
                    React__default["default"].createElement(AuthorComponent.AuthorComponent, { key: index$1.toString(), index: index$1, authors: article.authorMapping })
                  ),
                  !article.thumbnail && !defaultImage && article.source && React__default["default"].createElement(
                    'div',
                    { className: 'content-category-label' },
                    React__default["default"].createElement(
                      'div',
                      { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                      article.source
                    )
                  ),
                  React__default["default"].createElement(
                    'div',
                    { style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' } },
                    showCategory && article.contentCategory && React__default["default"].createElement(
                      'p',
                      {
                        className: 'article-category',
                        style: {
                          background: '#3FB618',
                          color: '#ffffff',
                          marginBottom: '.25rem',
                          display: 'inline-block',
                          padding: '0 .25rem',
                          fontSize: '.8rem'
                        } },
                      getContentCategory.getContentCategory(article.contentCategory.name, contentCategoryMapping)
                    ),
                    article.issueSection && article.issueSection.name && React__default["default"].createElement(
                      'p',
                      {
                        className: 'issueSection',
                        style: {
                          background: '#000000',
                          color: '#ffffff',
                          marginBottom: '.25rem',
                          marginLeft: '.25rem',
                          display: 'inline-block',
                          padding: '0 .25rem',
                          fontSize: '.8rem'
                        } },
                      article.issueSection.name
                    )
                  ),
                  showPubInfo && (article.issue || article.volume) && React__default["default"].createElement(
                    'div',
                    { className: 'pubInfo' },
                    article.volume && React__default["default"].createElement(
                      'p',
                      { className: 'qdeVolume' },
                      article.volume
                    ),
                    article.issue && React__default["default"].createElement(
                      'p',
                      { className: 'qdeIssue' },
                      article.issue
                    )
                  ),
                  showIntro && article.summary && React__default["default"].createElement(
                    'p',
                    { className: 'pt-2 card-text' },
                    entities.clean_html_1(article.summary)
                  )
                )
              )
            )
          );
        } else {
          return React__default["default"].createElement(
            visibilitySensor.VisibilitySensor,
            {
              key: article._id ? article._id : index$1,
              partialVisibility: true,
              onChange: function onChange(isVisible) {
                isVisible && changePageNumber(pageNumber, seoPaginate, pageview, router, currentPage, setCurrentPage);
              } },
            React__default["default"].createElement(
              React__default["default"].Fragment,
              null,
              React__default["default"].createElement(
                reactBootstrap.Media,
                {
                  key: article._id ? article._id : index$1,
                  className: 'feature-media',
                  style: { flexDirection: 'column', marginBottom: '1.25rem', paddingBottom: '1.25rem', borderBottom: '1px solid #ddd' } },
                (article.thumbnail && article.thumbnail.asset || defaultImage) && React__default["default"].createElement(
                  'a',
                  { href: article.url.current, className: 'feature-wrapper' },
                  React__default["default"].createElement(
                    index.LazyLoad,
                    { height: imageHeight, placeholder: React__default["default"].createElement(ImagePlaceholder, null) },
                    article.thumbnail && article.thumbnail.asset ? React__default["default"].createElement('img', { className: 'img-fluid', src: renderCardImage(article, client, imageHeight, imageWidth, imageMaxHeight, imageFit), alt: article.title }) : article.thumbnail ? React__default["default"].createElement('img', { src: article.thumbnail, className: 'mr-3', alt: article.title }) : React__default["default"].createElement('img', { src: defaultImage, src2: article.thumbnail, className: 'mr-3', width: '240', height: '135', alt: article.title })
                  ),
                  article.source && React__default["default"].createElement(
                    'div',
                    { className: 'content-category-label' },
                    React__default["default"].createElement(
                      'div',
                      { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                      article.source
                    )
                  )
                ),
                React__default["default"].createElement(
                  reactBootstrap.Media.Body,
                  null,
                  React__default["default"].createElement(
                    'a',
                    { href: article.url.current },
                    article.title && React__default["default"].createElement(
                      'h4',
                      { className: 'card-title', style: { fontWeight: '500', color: 'var(--gray-dark)', marginBottom: '.5rem' } },
                      article.title
                    )
                  ),
                  showPublished && !showTimeDiff && article.published && React__default["default"].createElement(
                    'p',
                    { className: 'card-text', style: { color: 'var(--dark)', margin: '.25rem 0' } },
                    moment.moment(article.published).format('MMMM DD, YYYY')
                  ),
                  showTimeDiff && article.published && React__default["default"].createElement(
                    'p',
                    { className: 'card-text', style: { color: '#464644', lineHeight: '1.25', fontSize: '.875rem', margin: '.25rem 0' } },
                    showTaxonomies && article.taxonomyMapping && article.taxonomyMapping.map(function (taxonomy, index) {
                      if (index > 3) {
                        return null;
                      }
                      if (index === 3) {
                        return React__default["default"].createElement(
                          React__default["default"].Fragment,
                          null,
                          React__default["default"].createElement(
                            'em',
                            { style: { marginRight: '.5rem' } },
                            '...'
                          )
                        );
                      }
                      if (index === 3) {
                        return React__default["default"].createElement(
                          React__default["default"].Fragment,
                          null,
                          React__default["default"].createElement(
                            'em',
                            { style: { marginRight: '.5rem' } },
                            '...'
                          )
                        );
                      }
                      return React__default["default"].createElement(
                        React__default["default"].Fragment,
                        null,
                        React__default["default"].createElement(
                          'em',
                          null,
                          taxonomy.name
                        ),
                        ' |',
                        ' '
                      );
                    }),
                    ' ',
                    React__default["default"].createElement(
                      'span',
                      { style: { display: 'inline-block' } },
                      timeDifferenceCalc(article.published)
                    )
                  ),
                  showAuthor && article.authorMapping && article.authorMapping.length > 0 && React__default["default"].createElement(
                    index.LazyLoad,
                    { height: 50 },
                    React__default["default"].createElement(AuthorComponent.AuthorComponent, { key: index$1.toString(), index: index$1, authors: article.authorMapping })
                  ),
                  !article.thumbnail && !defaultImage && article.source && React__default["default"].createElement(
                    'div',
                    { className: 'content-category-label' },
                    React__default["default"].createElement(
                      'div',
                      { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                      article.source
                    )
                  ),
                  React__default["default"].createElement(
                    'div',
                    { style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' } },
                    showCategory && article.contentCategory && React__default["default"].createElement(
                      'p',
                      {
                        className: 'article-category',
                        style: {
                          background: '#3FB618',
                          color: '#ffffff',
                          marginBottom: '.25rem',
                          display: 'inline-block',
                          padding: '0 .25rem',
                          fontSize: '.8rem'
                        } },
                      getContentCategory.getContentCategory(article.contentCategory.name, contentCategoryMapping)
                    ),
                    article.issueSection && article.issueSection.name && React__default["default"].createElement(
                      'p',
                      {
                        className: 'issueSection',
                        style: {
                          background: '#000000',
                          color: '#ffffff',
                          marginBottom: '.25rem',
                          marginLeft: '.25rem',
                          display: 'inline-block',
                          padding: '0 .25rem',
                          fontSize: '.8rem'
                        } },
                      article.issueSection.name
                    )
                  ),
                  showPubInfo && (article.issue || article.volume) && React__default["default"].createElement(
                    'div',
                    { className: 'pubInfo' },
                    article.volume && React__default["default"].createElement(
                      'p',
                      { className: 'qdeVolume' },
                      article.volume
                    ),
                    article.issue && React__default["default"].createElement(
                      'p',
                      { className: 'qdeIssue' },
                      article.issue
                    )
                  ),
                  showIntro && article.summary && React__default["default"].createElement(
                    'p',
                    { className: 'pt-2 card-text' },
                    entities.clean_html_1(article.summary)
                  )
                )
              )
            )
          );
        }
      } else if (article._type === 'lg-infeed' && article.adUnit) {
        return React__default["default"].createElement(ADlgInfeed.ADlgInfeed, _extends._extends({ index: index$1 }, article));
      } else if (article._type === 'brandInsightAd' && article.adUnit) {
        return React__default["default"].createElement(ADInfeed.ADInfeed, { index: index$1, infeedAd: article });
      }
      if ((brandInsightAd ? index$1 > heroContent + featureCount : index$1 + 1 > heroContent + featureCount) && (!article._type || !['lg-infeed', 'brandInsightAd'].includes(article._type))) {
        return React__default["default"].createElement(
          visibilitySensor.VisibilitySensor,
          {
            key: article._id ? article._id : index$1,
            onChange: function onChange(isVisible) {
              // Passing 'articleCount' instead of index because index will be including the indexes of ads whereas articleCount will be having index of artilce only.
              isVisible && changePageNumber(pageNumber, seoPaginate, pageview, router, currentPage, setCurrentPage, itemsPerPage, article.articleCount ? article.articleCount : index$1);
            } },
          React__default["default"].createElement(
            React__default["default"].Fragment,
            null,
            React__default["default"].createElement(
              reactBootstrap.Media,
              {
                key: article._id ? article._id : index$1,
                style: { flexDirection: 'row', marginBottom: '1.25rem', paddingBottom: '1.25rem', borderBottom: '1px solid #ddd' } },
              (article.thumbnail && article.thumbnail.asset || defaultImage) && React__default["default"].createElement(
                'a',
                { href: mapping[contentCategoryName] + '/' + article.url.current, className: 'img-wrapper' },
                React__default["default"].createElement(
                  index.LazyLoad,
                  { height: imageHeight, placeholder: React__default["default"].createElement(ImagePlaceholder, null) },
                  article.thumbnail && article.thumbnail.asset ? React__default["default"].createElement('img', { className: 'mr-3 img-fluid', src: renderCardImage(article, client, imageHeight, imageWidth, imageMaxHeight, imageFit), alt: article.title }) : article.thumbnail ? React__default["default"].createElement('img', { src: article.thumbnail, className: 'mr-3', alt: article.title }) : React__default["default"].createElement('img', { src: defaultImage, src2: article.thumbnail, className: 'mr-3', width: '240', height: '135', alt: article.title })
                ),
                article.source && React__default["default"].createElement(
                  'div',
                  { className: 'content-category-label' },
                  React__default["default"].createElement(
                    'div',
                    { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                    article.source
                  )
                )
              ),
              React__default["default"].createElement(
                reactBootstrap.Media.Body,
                null,
                React__default["default"].createElement(
                  'a',
                  { href: mapping[contentCategoryName] + '/' + article.url.current },
                  article.title && React__default["default"].createElement(
                    'h4',
                    { className: 'card-title', style: { fontWeight: '500', color: 'var(--gray-dark)', marginBottom: '.5rem' } },
                    article.title
                  )
                ),
                showPublished && !showTimeDiff && article.published && React__default["default"].createElement(
                  'p',
                  { className: 'card-text', style: { color: 'var(--dark)', margin: '.25rem 0' } },
                  moment.moment(article.published).format('MMMM DD, YYYY')
                ),
                showTimeDiff && article.published && React__default["default"].createElement(
                  'p',
                  { className: 'card-text', style: { color: '#464644', lineHeight: '1.25', fontSize: '.875rem', margin: '.25rem 0' } },
                  showTaxonomies && article.taxonomyMapping && article.taxonomyMapping.map(function (taxonomy, index) {
                    if (index > 3) {
                      return null;
                    }
                    if (index === 3) {
                      return React__default["default"].createElement(
                        React__default["default"].Fragment,
                        null,
                        React__default["default"].createElement(
                          'em',
                          { style: { marginRight: '.5rem' } },
                          '...'
                        )
                      );
                    }
                    return React__default["default"].createElement(
                      React__default["default"].Fragment,
                      null,
                      React__default["default"].createElement(
                        'em',
                        null,
                        taxonomy.name
                      ),
                      ' |',
                      ' '
                    );
                  }),
                  ' ',
                  React__default["default"].createElement(
                    'span',
                    { style: { display: 'inline-block' } },
                    timeDifferenceCalc(article.published)
                  )
                ),
                React__default["default"].createElement(
                  'div',
                  { className: 'author-sec', style: { lineHeight: 1.5 } },
                  showAuthor && article.authorMapping && article.authorMapping.length > 0 && React__default["default"].createElement(
                    index.LazyLoad,
                    { height: 50 },
                    React__default["default"].createElement(AuthorComponent.AuthorComponent, { key: index$1.toString(), index: index$1, authors: article.authorMapping })
                  )
                ),
                !article.thumbnail && !defaultImage && article.source && React__default["default"].createElement(
                  'div',
                  { className: 'content-category-label' },
                  React__default["default"].createElement(
                    'div',
                    { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                    article.source
                  )
                ),
                React__default["default"].createElement(
                  'div',
                  { style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' } },
                  showCategory && article.contentCategory && React__default["default"].createElement(
                    'p',
                    {
                      className: 'article-category',
                      style: {
                        background: '#3FB618',
                        color: '#ffffff',
                        marginBottom: '.25rem',
                        display: 'inline-block',
                        padding: '0 .25rem',
                        fontSize: '.8rem'
                      } },
                    getContentCategory.getContentCategory(article.contentCategory.name, contentCategoryMapping)
                  ),
                  article.issueSection && article.issueSection.name && React__default["default"].createElement(
                    'p',
                    {
                      className: 'issueSection',
                      style: {
                        background: '#000000',
                        color: '#ffffff',
                        marginBottom: '.25rem',
                        marginLeft: '.25rem',
                        display: 'inline-block',
                        padding: '0 .25rem',
                        fontSize: '.8rem'
                      } },
                    article.issueSection.name
                  )
                ),
                showPubInfo && (article.issue || article.volume) && React__default["default"].createElement(
                  'div',
                  { className: 'pubInfo' },
                  article.volume && React__default["default"].createElement(
                    'p',
                    { className: 'qdeVolume' },
                    article.volume
                  ),
                  article.issue && React__default["default"].createElement(
                    'p',
                    { className: 'qdeIssue' },
                    article.issue
                  )
                ),
                showIntro && article.summary && React__default["default"].createElement(
                  'p',
                  { className: 'pt-2 card-text' },
                  entities.clean_html_1(article.summary)
                )
              )
            ),
            React__default["default"].createElement(
              'div',
              null,
              main.main_43 && rightItems && (index$1 + 1) % numberOfItemsBeforeAd === 0 && renderMobileAd(index$1, numberOfItemsBeforeAd, rightItems)
            )
          )
        );
      } else return null;
    }) :
    // For Javascript Disabled Cases
    React__default["default"].createElement(
      'noscript',
      null,
      data.map(function (article, index$1) {
        var pageNumber = article.pageNumber || values.page;
        var contentCategoryName = article.contentCategory ? article.contentCategory.name : 'Articles';

        if (article._type === 'feature') {
          featureCount++;
          if (article.blank || checkExternalUrl(article.url.current)) {
            return React__default["default"].createElement(
              visibilitySensor.VisibilitySensor,
              {
                key: article._id ? article._id : index$1,
                partialVisibility: true,
                onChange: function onChange(isVisible) {
                  isVisible && changePageNumber(pageNumber, seoPaginate, pageview, router, currentPage, setCurrentPage);
                } },
              React__default["default"].createElement(
                React__default["default"].Fragment,
                null,
                React__default["default"].createElement(
                  reactBootstrap.Media,
                  {
                    key: article._id ? article._id : index$1,
                    className: 'feature-media',
                    style: { flexDirection: 'column', marginBottom: '1.25rem', paddingBottom: '1.25rem', borderBottom: '1px solid #ddd' } },
                  (article.thumbnail && article.thumbnail.asset || defaultImage) && React__default["default"].createElement(
                    'a',
                    { rel: 'noopener', href: article.url.current, target: '_blank', className: 'feature-wrapper' },
                    React__default["default"].createElement(
                      index.LazyLoad,
                      { height: imageHeight, placeholder: React__default["default"].createElement(ImagePlaceholder, null) },
                      article.thumbnail && article.thumbnail.asset ? React__default["default"].createElement('img', { className: 'img-fluid', src: renderCardImage(article, client, imageHeight, imageWidth, imageMaxHeight, imageFit), alt: article.title }) : article.thumbnail ? React__default["default"].createElement('img', { src: article.thumbnail, className: 'mr-3', alt: article.title }) : React__default["default"].createElement('img', { src: defaultImage, src2: article.thumbnail, className: 'mr-3', width: '240', height: '135', alt: article.title })
                    ),
                    article.source && React__default["default"].createElement(
                      'div',
                      { className: 'content-category-label' },
                      React__default["default"].createElement(
                        'div',
                        { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                        article.source
                      )
                    )
                  ),
                  React__default["default"].createElement(
                    reactBootstrap.Media.Body,
                    null,
                    React__default["default"].createElement(
                      'a',
                      { rel: 'noopener', href: article.url.current, target: '_blank' },
                      article.title && React__default["default"].createElement(
                        'h4',
                        { className: 'card-title', style: { fontWeight: '500', color: 'var(--gray-dark)', marginBottom: '.5rem' } },
                        article.title
                      )
                    ),
                    showPublished && article.published && React__default["default"].createElement(
                      'p',
                      { className: 'card-text', style: { color: 'var(--dark)', marginBottom: '.25rem' } },
                      moment.moment(article.published).format('MMMM DD, YYYY')
                    ),
                    showTimeDiff && article.published && React__default["default"].createElement(
                      'p',
                      { className: 'card-text', style: { color: '#464644', lineHeight: '1.25', fontSize: '.875rem', margin: '.25rem 0' } },
                      showTaxonomies && article.taxonomyMapping && article.taxonomyMapping.map(function (taxonomy, index) {
                        if (index > 3) {
                          return null;
                        }
                        if (index === 3) {
                          return React__default["default"].createElement(
                            React__default["default"].Fragment,
                            null,
                            React__default["default"].createElement(
                              'em',
                              { style: { marginRight: '.5rem' } },
                              '...'
                            )
                          );
                        }
                        return React__default["default"].createElement(
                          React__default["default"].Fragment,
                          null,
                          React__default["default"].createElement(
                            'em',
                            null,
                            taxonomy.name
                          ),
                          ' |',
                          ' '
                        );
                      }),
                      ' ',
                      React__default["default"].createElement(
                        'span',
                        { style: { display: 'inline-block' } },
                        timeDifferenceCalc(article.published)
                      )
                    ),
                    showAuthor && article.authorMapping && article.authorMapping.length > 0 && React__default["default"].createElement(
                      index.LazyLoad,
                      { height: 50 },
                      React__default["default"].createElement(AuthorComponent.AuthorComponent, { key: index$1.toString(), index: index$1, authors: article.authorMapping })
                    ),
                    !article.thumbnail && !defaultImage && article.source && React__default["default"].createElement(
                      'div',
                      { className: 'content-category-label' },
                      React__default["default"].createElement(
                        'div',
                        { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                        article.source
                      )
                    ),
                    React__default["default"].createElement(
                      'div',
                      { style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' } },
                      showCategory && article.contentCategory && React__default["default"].createElement(
                        'p',
                        {
                          className: 'article-category',
                          style: {
                            background: '#3FB618',
                            color: '#ffffff',
                            marginBottom: '.25rem',
                            display: 'inline-block',
                            padding: '0 .25rem',
                            fontSize: '.8rem'
                          } },
                        getContentCategory.getContentCategory(article.contentCategory.name, contentCategoryMapping)
                      ),
                      article.issueSection && article.issueSection.name && React__default["default"].createElement(
                        'p',
                        {
                          className: 'issueSection',
                          style: {
                            background: '#000000',
                            color: '#ffffff',
                            marginBottom: '.25rem',
                            marginLeft: '.25rem',
                            display: 'inline-block',
                            padding: '0 .25rem',
                            fontSize: '.8rem'
                          } },
                        article.issueSection.name
                      )
                    ),
                    showPubInfo && (article.issue || article.volume) && React__default["default"].createElement(
                      'div',
                      { className: 'pubInfo' },
                      article.volume && React__default["default"].createElement(
                        'p',
                        { className: 'qdeVolume' },
                        article.volume
                      ),
                      article.issue && React__default["default"].createElement(
                        'p',
                        { className: 'qdeIssue' },
                        article.issue
                      )
                    ),
                    showIntro && article.summary && React__default["default"].createElement(
                      'p',
                      { className: 'pt-2 card-text' },
                      entities.clean_html_1(article.summary)
                    )
                  )
                )
              )
            );
          } else {
            return React__default["default"].createElement(
              visibilitySensor.VisibilitySensor,
              {
                key: article._id ? article._id : index$1,
                partialVisibility: true,
                onChange: function onChange(isVisible) {
                  isVisible && changePageNumber(pageNumber, seoPaginate, pageview, router, currentPage, setCurrentPage);
                } },
              React__default["default"].createElement(
                React__default["default"].Fragment,
                null,
                React__default["default"].createElement(
                  reactBootstrap.Media,
                  {
                    key: article._id ? article._id : index$1,
                    className: 'feature-media',
                    style: { flexDirection: 'column', marginBottom: '1.25rem', paddingBottom: '1.25rem', borderBottom: '1px solid #ddd' } },
                  (article.thumbnail && article.thumbnail.asset || defaultImage) && React__default["default"].createElement(
                    'a',
                    { href: article.url.current, className: 'feature-wrapper' },
                    React__default["default"].createElement(
                      index.LazyLoad,
                      { height: imageHeight, placeholder: React__default["default"].createElement(ImagePlaceholder, null) },
                      article.thumbnail && article.thumbnail.asset ? React__default["default"].createElement('img', { className: 'img-fluid', src: renderCardImage(article, client, imageHeight, imageWidth, imageMaxHeight, imageFit), alt: article.title }) : article.thumbnail ? React__default["default"].createElement('img', { src: article.thumbnail, className: 'mr-3', alt: article.title }) : React__default["default"].createElement('img', { src: defaultImage, src2: article.thumbnail, className: 'mr-3', width: '240', height: '135', alt: article.title })
                    ),
                    article.source && React__default["default"].createElement(
                      'div',
                      { className: 'content-category-label' },
                      React__default["default"].createElement(
                        'div',
                        { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                        article.source
                      )
                    )
                  ),
                  React__default["default"].createElement(
                    reactBootstrap.Media.Body,
                    null,
                    React__default["default"].createElement(
                      'a',
                      { href: article.url.current },
                      article.title && React__default["default"].createElement(
                        'h4',
                        { className: 'card-title', style: { fontWeight: '500', color: 'var(--gray-dark)', marginBottom: '.5rem' } },
                        article.title
                      )
                    ),
                    showPublished && article.published && React__default["default"].createElement(
                      'p',
                      { className: 'card-text', style: { color: 'var(--dark)', marginBottom: '.25rem' } },
                      moment.moment(article.published).format('MMMM DD, YYYY')
                    ),
                    showTimeDiff && article.published && React__default["default"].createElement(
                      'p',
                      { className: 'card-text', style: { color: '#464644', lineHeight: '1.25', fontSize: '.875rem', margin: '.25rem 0' } },
                      showTaxonomies && article.taxonomyMapping && article.taxonomyMapping.map(function (taxonomy, index) {
                        if (index > 3) {
                          return null;
                        }
                        if (index === 3) {
                          return React__default["default"].createElement(
                            React__default["default"].Fragment,
                            null,
                            React__default["default"].createElement(
                              'em',
                              { style: { marginRight: '.5rem' } },
                              '...'
                            )
                          );
                        }
                        return React__default["default"].createElement(
                          React__default["default"].Fragment,
                          null,
                          React__default["default"].createElement(
                            'em',
                            null,
                            taxonomy.name
                          ),
                          ' |',
                          ' '
                        );
                      }),
                      ' ',
                      React__default["default"].createElement(
                        'span',
                        { style: { display: 'inline-block' } },
                        timeDifferenceCalc(article.published)
                      )
                    ),
                    showAuthor && article.authorMapping && article.authorMapping.length > 0 && React__default["default"].createElement(
                      index.LazyLoad,
                      { height: 50 },
                      React__default["default"].createElement(AuthorComponent.AuthorComponent, { key: index$1.toString(), index: index$1, authors: article.authorMapping })
                    ),
                    !article.thumbnail && !defaultImage && article.source && React__default["default"].createElement(
                      'div',
                      { className: 'content-category-label' },
                      React__default["default"].createElement(
                        'div',
                        { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                        article.source
                      )
                    ),
                    React__default["default"].createElement(
                      'div',
                      { style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' } },
                      showCategory && article.contentCategory && React__default["default"].createElement(
                        'p',
                        {
                          className: 'article-category',
                          style: {
                            background: '#3FB618',
                            color: '#ffffff',
                            marginBottom: '.25rem',
                            display: 'inline-block',
                            padding: '0 .25rem',
                            fontSize: '.8rem'
                          } },
                        getContentCategory.getContentCategory(article.contentCategory.name, contentCategoryMapping)
                      ),
                      article.issueSection && article.issueSection.name && React__default["default"].createElement(
                        'p',
                        {
                          className: 'issueSection',
                          style: {
                            background: '#000000',
                            color: '#ffffff',
                            marginBottom: '.25rem',
                            marginLeft: '.25rem',
                            display: 'inline-block',
                            padding: '0 .25rem',
                            fontSize: '.8rem'
                          } },
                        article.issueSection.name
                      )
                    ),
                    showPubInfo && (article.issue || article.volume) && React__default["default"].createElement(
                      'div',
                      { className: 'pubInfo' },
                      article.volume && React__default["default"].createElement(
                        'p',
                        { className: 'qdeVolume' },
                        article.volume
                      ),
                      article.issue && React__default["default"].createElement(
                        'p',
                        { className: 'qdeIssue' },
                        article.issue
                      )
                    ),
                    showIntro && article.summary && React__default["default"].createElement(
                      'p',
                      { className: 'pt-2 card-text' },
                      entities.clean_html_1(article.summary)
                    )
                  )
                )
              )
            );
          }
        } else if (article._type === 'lg-infeed' && article.adUnit) {
          return React__default["default"].createElement(ADlgInfeed.ADlgInfeed, _extends._extends({ index: index$1 }, article));
        } else if (article._type === 'brandInsightAd' && article.adUnit) {
          return React__default["default"].createElement(ADInfeed.ADInfeed, { index: index$1, infeedAd: article });
        }
        if ((brandInsightAd ? index$1 > heroContent + featureCount : index$1 + 1 > heroContent + featureCount) && (!article._type || !['lg-infeed', 'brandInsightAd'].includes(article._type))) {
          return React__default["default"].createElement(
            visibilitySensor.VisibilitySensor,
            {
              key: article._id ? article._id : index$1,
              onChange: function onChange(isVisible) {
                // Passing 'articleCount' instead of index because index will be including the indexes of ads whereas articleCount will be having index of artilce only.
                isVisible && changePageNumber(pageNumber, seoPaginate, pageview, router, currentPage, setCurrentPage, itemsPerPage, article.articleCount ? article.articleCount : index$1);
              } },
            React__default["default"].createElement(
              React__default["default"].Fragment,
              null,
              React__default["default"].createElement(
                reactBootstrap.Media,
                {
                  key: article._id ? article._id : index$1,
                  style: { flexDirection: 'row', marginBottom: '1.25rem', paddingBottom: '1.25rem', borderBottom: '1px solid #ddd' } },
                (article.thumbnail && article.thumbnail.asset || defaultImage) && React__default["default"].createElement(
                  'a',
                  { href: mapping[contentCategoryName] + '/' + article.url.current, className: 'img-wrapper' },
                  React__default["default"].createElement(
                    index.LazyLoad,
                    { height: imageHeight, placeholder: React__default["default"].createElement(ImagePlaceholder, null) },
                    article.thumbnail && article.thumbnail.asset ? React__default["default"].createElement('img', { className: 'mr-3 img-fluid', src: renderCardImage(article, client, imageHeight, imageWidth, imageMaxHeight, imageFit), alt: article.title }) : article.thumbnail ? React__default["default"].createElement('img', { src: article.thumbnail, className: 'mr-3', alt: article.title }) : React__default["default"].createElement('img', { src: defaultImage, src2: article.thumbnail, className: 'mr-3', width: '240', height: '135', alt: article.title })
                  ),
                  article.source && React__default["default"].createElement(
                    'div',
                    { className: 'content-category-label' },
                    React__default["default"].createElement(
                      'div',
                      { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                      article.source
                    )
                  )
                ),
                React__default["default"].createElement(
                  reactBootstrap.Media.Body,
                  null,
                  React__default["default"].createElement(
                    'a',
                    { href: mapping[contentCategoryName] + '/' + article.url.current },
                    article.title && React__default["default"].createElement(
                      'h4',
                      { className: 'card-title', style: { fontWeight: '500', color: 'var(--gray-dark)', marginBottom: '.5rem' } },
                      article.title
                    )
                  ),
                  showPublished && article.published && React__default["default"].createElement(
                    'p',
                    { className: 'card-text', style: { color: 'var(--dark)', marginBottom: '.25rem' } },
                    moment.moment(article.published).format('MMMM DD, YYYY')
                  ),
                  showTimeDiff && article.published && React__default["default"].createElement(
                    'p',
                    { className: 'card-text', style: { color: '#464644', lineHeight: '1.25', fontSize: '.875rem', margin: '.25rem 0' } },
                    showTaxonomies && article.taxonomyMapping && article.taxonomyMapping.map(function (taxonomy, index) {
                      if (index > 3) {
                        return null;
                      }
                      if (index === 3) {
                        return React__default["default"].createElement(
                          React__default["default"].Fragment,
                          null,
                          React__default["default"].createElement(
                            'em',
                            { style: { marginRight: '.5rem' } },
                            '...'
                          )
                        );
                      }
                      return React__default["default"].createElement(
                        React__default["default"].Fragment,
                        null,
                        React__default["default"].createElement(
                          'em',
                          null,
                          taxonomy.name
                        ),
                        ' |',
                        ' '
                      );
                    }),
                    ' ',
                    React__default["default"].createElement(
                      'span',
                      { style: { display: 'inline-block' } },
                      timeDifferenceCalc(article.published)
                    )
                  ),
                  React__default["default"].createElement(
                    'div',
                    { className: 'author-sec', style: { lineHeight: 1.5 } },
                    showAuthor && article.authorMapping && article.authorMapping.length > 0 && React__default["default"].createElement(
                      index.LazyLoad,
                      { height: 50 },
                      React__default["default"].createElement(AuthorComponent.AuthorComponent, { key: index$1.toString(), index: index$1, authors: article.authorMapping })
                    )
                  ),
                  !article.thumbnail && !defaultImage && article.source && React__default["default"].createElement(
                    'div',
                    { className: 'content-category-label' },
                    React__default["default"].createElement(
                      'div',
                      { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                      article.source
                    )
                  ),
                  React__default["default"].createElement(
                    'div',
                    { style: { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' } },
                    showCategory && article.contentCategory && React__default["default"].createElement(
                      'p',
                      {
                        className: 'article-category',
                        style: {
                          background: '#3FB618',
                          color: '#ffffff',
                          marginBottom: '.25rem',
                          display: 'inline-block',
                          padding: '0 .25rem',
                          fontSize: '.8rem'
                        } },
                      getContentCategory.getContentCategory(article.contentCategory.name, contentCategoryMapping)
                    ),
                    article.issueSection && article.issueSection.name && React__default["default"].createElement(
                      'p',
                      {
                        className: 'issueSection',
                        style: {
                          background: '#000000',
                          color: '#ffffff',
                          marginBottom: '.25rem',
                          marginLeft: '.25rem',
                          display: 'inline-block',
                          padding: '0 .25rem',
                          fontSize: '.8rem'
                        } },
                      article.issueSection.name
                    )
                  ),
                  showPubInfo && (article.issue || article.volume) && React__default["default"].createElement(
                    'div',
                    { className: 'pubInfo' },
                    article.volume && React__default["default"].createElement(
                      'p',
                      { className: 'qdeVolume' },
                      article.volume
                    ),
                    article.issue && React__default["default"].createElement(
                      'p',
                      { className: 'qdeIssue' },
                      article.issue
                    )
                  ),
                  showIntro && article.summary && React__default["default"].createElement(
                    'p',
                    { className: 'pt-2 card-text' },
                    entities.clean_html_1(article.summary)
                  )
                )
              ),
              React__default["default"].createElement(
                'div',
                null,
                main.main_43 && rightItems && (index$1 + 1) % numberOfItemsBeforeAd === 0 && renderMobileAd(index$1, numberOfItemsBeforeAd, rightItems)
              )
            )
          );
        } else return null;
      })
    ) : React__default["default"].createElement(
      'div',
      null,
      React__default["default"].createElement(
        'h5',
        null,
        React__default["default"].createElement(
          'em',
          null,
          'New content coming soon, please check back later.'
        )
      )
    ),
    React__default["default"].createElement(
      'style',
      { jsx: 'true' },
      '\n          .displayLabelThumb {\n            margin: 0 auto;\n            margin-top: -1.25rem;\n            background-color: white;\n            position: relative;\n          }\n          .content-category-label {\n            margin: 0.5rem 0;\n            display: block;\n          }\n          .sanityDisplayLabel {\n            margin: 0.5rem 0;\n            border: 1px solid black;\n            width: fit-content;\n            width: -moz-fit-content;\n            padding: 5px;\n            color: #484848;\n            border-radius: 2px;\n          }\n          .feature-media > .media-body {\n            -webkit-box-flex: none;\n            -ms-flex: none;\n            flex: none;\n          }\n          .img-wrapper img {\n            max-height: 240px;\n            height: auto;\n            width: 100%;\n            object-fit: contain;\n          }\n          .feature-wrapper {\n            height: 100%;\n            width: 100%;\n          }\n          .feature-wrapper img {\n            width: 100%;\n            margin-bottom: 1em;\n          }\n          @media only screen and (min-width: 768px) {\n            .img-wrapper > img {\n              padding-right: 1em;\n            }\n          }\n          @media only screen and (max-width: 767px) {\n            .sanityDisplayLabel {\n              max-width: 100%;\n            }\n            .img-wrapper {\n              width: 100%;\n            }\n            .img-wrapper img {\n              padding-bottom: 1em;\n            }\n            .media {\n              flex-direction: column !important;\n            }\n          }\n        '
    )
  );
};

var ImagePlaceholder = function ImagePlaceholder() {
  return React__default["default"].createElement(
    React__default["default"].Fragment,
    null,
    React__default["default"].createElement('div', { className: 'queuedeck-exp-image-placeholder' }),
    React__default["default"].createElement(
      'style',
      { jsx: 'true' },
      '\n      .queuedeck-exp-image-placeholder {\n        width: 240px;\n        height: 0;\n        padding-top: calc(240px * 9 / 16);\n        margin: 0 1rem 0 0;\n      }\n      @media only screen and (max-width: 767px) {\n        .queuedeck-exp-image-placeholder {\n          width: 100%;\n          height: 0;\n          padding-top: calc(100% * 9 / 16);\n          margin: 0 0 1rem 0;\n        }\n      }\n    '
    )
  );
};

var renderMobileAd = function renderMobileAd(index, numberOfItemsBeforeAd, rightItems) {
  var i = numberOfItemsBeforeAd < 6 ? 0 : ((index + 1) / numberOfItemsBeforeAd - 1) % rightItems.length;
  return React__default["default"].createElement(
    'div',
    { style: { display: 'flex', flex: '1 0 auto' } },
    rightItems[i].component
  );
};

var usePrevious = function usePrevious(value) {
  var ref = React.useRef();
  React.useEffect(function () {
    ref.current = value;
  });
  return ref.current;
};

var QueueDeckExpanded = function QueueDeckExpanded(props) {
  var router = Router.useRouter();

  // Logging GA Pageview on path change
  var prevPath = usePrevious(lodash.lodash.get(router, 'asPath', undefined));
  React.useEffect(function () {
    var pageview = props.pageview;

    var currentPath = router.asPath;
    if (prevPath && prevPath !== currentPath && pageview) {
      pageview(router.asPath);
    }
  }, [router]);

  var initialData = props.dataRecord,
      client = props.client,
      params = props.params,
      query = props.query,
      autoScroll = props.autoScroll,
      pointer = props.pointer,
      pointerArray = props.pointerArray,
      mapping = props.mapping,
      seoPaginate = props.seoPaginate,
      pageview = props.pageview,
      defaultImage = props.defaultImage,
      showAuthor = props.showAuthor,
      showCategory = props.showCategory,
      imageHeight = props.imageHeight,
      imageWidth = props.imageWidth,
      imageMaxHeight = props.imageMaxHeight,
      imageFit = props.imageFit,
      rightItems = props.rightItems,
      brandInsightAd = props.brandInsightAd,
      _props$nextPagePostsC = props.nextPagePostsCount,
      nextPagePostsCount = _props$nextPagePostsC === undefined ? 3 : _props$nextPagePostsC,
      _props$showBI = props.showBI,
      showBI = _props$showBI === undefined ? false : _props$showBI,
      _props$heroContent = props.heroContent,
      heroContent = _props$heroContent === undefined ? 0 : _props$heroContent,
      _props$lgInfeedAd = props.lgInfeedAd,
      lgInfeedAd = _props$lgInfeedAd === undefined ? false : _props$lgInfeedAd,
      _props$showPubInfo = props.showPubInfo,
      showPubInfo = _props$showPubInfo === undefined ? false : _props$showPubInfo,
      _props$showTimeDiff = props.showTimeDiff,
      showTimeDiff = _props$showTimeDiff === undefined ? false : _props$showTimeDiff,
      _props$showTaxonomies = props.showTaxonomies,
      showTaxonomies = _props$showTaxonomies === undefined ? false : _props$showTaxonomies,
      _props$showIntro = props.showIntro,
      showIntro = _props$showIntro === undefined ? true : _props$showIntro,
      _props$contentCategor = props.contentCategoryMapping,
      contentCategoryMapping = _props$contentCategor === undefined ? [] : _props$contentCategor;
  var initialCurrentPage = props.currentPage,
      showPublished = props.showPublished;

  var _useState3 = React.useState(initialData),
      _useState4 = slicedToArray._slicedToArray(_useState3, 2),
      data = _useState4[0],
      setData = _useState4[1];

  var _useState5 = React.useState(true),
      _useState6 = slicedToArray._slicedToArray(_useState5, 2),
      scrolling = _useState6[0],
      setScrolling = _useState6[1];

  var _useState7 = React.useState(initialCurrentPage || 1),
      _useState8 = slicedToArray._slicedToArray(_useState7, 2),
      currentPage = _useState8[0],
      setCurrentPage = _useState8[1];

  var _useState9 = React.useState(initialData ? initialData.length : 0),
      _useState10 = slicedToArray._slicedToArray(_useState9, 2),
      lastDataSize = _useState10[0],
      setLastDataSize = _useState10[1];

  var _useState11 = React.useState({
    from: params ? params.from : 0,
    to: params ? params.to : 0,
    page: initialCurrentPage ? initialCurrentPage : 1
  }),
      _useState12 = slicedToArray._slicedToArray(_useState11, 2),
      values = _useState12[0],
      setValues = _useState12[1];

  var itemsPerPage = params && params.itemsPerPage ? params.itemsPerPage : 10;

  var prevValues = usePrevious(values);

  var renderManualPagination = function renderManualPagination(currentPage) {
    return React__default["default"].createElement(
      'div',
      { className: 'd-flex justify-content-between' },
      currentPage && currentPage > 1 && React__default["default"].createElement(
        'a',
        { href: '?page=' + (currentPage - 1) },
        '<< Previous'
      ),
      !(lastDataSize < itemsPerPage) && nextPagePostsCount > 0 && React__default["default"].createElement(
        'a',
        { href: '?page=' + (currentPage + 1) },
        'Next >>'
      )
    );
  };

  //  check for change in filter parameters from client side and refresh the page
  React.useEffect(function () {
    if (initialData && data !== initialData && initialData.length >= 0) {
      setData(initialData);
      setCurrentPage(initialCurrentPage ? initialCurrentPage : 1);
      setValues({
        from: params ? params.from : 0,
        to: params ? params.to : 0,
        page: initialCurrentPage ? initialCurrentPage : 1
      });
      if (initialData.length > 0) {
        setScrolling(true);
      }
    }
  }, [initialData]);

  React.useEffect(function () {
    if (prevValues) {
      if (values.page !== prevValues.page && values.from !== prevValues.from && values.to !== prevValues.to) {
        loadData(values, query, client, params, setData, setScrolling, setLastDataSize, pointer, pointerArray);
      }
    }
  }, [values, prevValues, query, client, params, setData, setScrolling, setLastDataSize, pointer, pointerArray]);

  // useEffect(() => {
  //   document.addEventListener('scroll', trackScrolling)
  //   return () => {
  //     document.removeEventListener('scroll', trackScrolling)
  //   }
  // }, [currentPage])

  // const trackScrolling = (current) => {
  //   if (window.pageYOffset === 0) {
  //     if (currentPage > 1) {
  //       changePageNumber(1, seoPaginate, pageview, router, currentPage, setCurrentPage, itemsPerPage, 1)
  //     }
  //   }
  // }

  return React__default["default"].createElement(
    'div',
    null,
    autoScroll ? React__default["default"].createElement(
      React__default["default"].Fragment,
      null,
      React__default["default"].createElement(
        index_es.InfiniteScroll,
        { dataLength: data && data.length, next: function next() {
            return loadMore(values, setValues, itemsPerPage);
          }, hasMore: scrolling, scrollThreshold: 0.9 },
        React__default["default"].createElement(
          reactBootstrap.Container,
          null,
          cardLoader(data, client, mapping, values, seoPaginate, pageview, router, currentPage, setCurrentPage, showPublished, defaultImage, showAuthor, showCategory, imageHeight, imageWidth, imageMaxHeight, imageFit, rightItems, brandInsightAd, showBI, itemsPerPage, heroContent, lgInfeedAd, showPubInfo, contentCategoryMapping, showTimeDiff, showTaxonomies, showIntro)
        )
      ),
      React__default["default"].createElement(
        'noscript',
        null,
        renderManualPagination(currentPage)
      )
    ) : React__default["default"].createElement(
      React__default["default"].Fragment,
      null,
      React__default["default"].createElement(
        reactBootstrap.Container,
        null,
        cardLoader(data, client, mapping, values, seoPaginate, pageview, router, currentPage, setCurrentPage, showPublished, defaultImage, showAuthor, showCategory, imageHeight, imageWidth, imageMaxHeight, imageFit, rightItems, brandInsightAd, showBI, itemsPerPage, heroContent, lgInfeedAd, showPubInfo, contentCategoryMapping, showTimeDiff, showTaxonomies, showIntro)
      ),
      React__default["default"].createElement(
        'div',
        { style: { padding: '0px 10px' } },
        scrolling ? React__default["default"].createElement(
          'button',
          {
            className: 'load-more-btn',
            style: { margin: 'auto', width: '100%' },
            onClick: function onClick(e) {
              loadMore(values, setValues, itemsPerPage);
            } },
          'Load More'
        ) : React__default["default"].createElement(
          'p',
          { style: { textAlign: 'center' } },
          React__default["default"].createElement(
            'b',
            null,
            'End of data'
          )
        )
      ),
      React__default["default"].createElement(
        'noscript',
        null,
        renderManualPagination(currentPage)
      )
    )
  );
};

module.exports = QueueDeckExpanded;
