import { _ as _slicedToArray } from './slicedToArray-ca2c8b8d.js';
import React, { useState, useEffect } from 'react';
import DFPAdSlot from './AdSlot.js';
import './_commonjsHelpers-0c4b6f40.js';
import './web.dom.iterable-fdf034f5.js';
import './core.get-iterator-method-e903ff31.js';
import './extends-dc6a71fd.js';
import './_object-pie-133f504a.js';
import 'prop-types';
import './index-2446af28.js';
import './events-6c3a7a63.js';
import './debounce-533d9748.js';
import './isSymbol-a7e9aafe.js';
import './toNumber-5aeba6e7.js';
import './Beam.js';
import './stringify-c21932b3.js';
import './asyncToGenerator-b4dfe691.js';
import './_library-528f1934.js';
import './_iter-detect-f089461c.js';
import './Segment.js';
import './main-b5c5aac1.js';

//  Webcast AD : New AD with size [200,100] that is to be renderedin the LeftNav between the spotlight and subnavigation.
var ADWebcast = function ADWebcast(_ref) {
  var webcastAd = _ref.webcastAd,
      _ref$minScreenWidth = _ref.minScreenWidth,
      minScreenWidth = _ref$minScreenWidth === undefined ? 1200 : _ref$minScreenWidth,
      _ref$refreshFlag = _ref.refreshFlag,
      refreshFlag = _ref$refreshFlag === undefined ? false : _ref$refreshFlag;
  var className = webcastAd.className,
      _webcastAd$slotId = webcastAd.slotId,
      slotId = _webcastAd$slotId === undefined ? 'webcast-ad' : _webcastAd$slotId,
      adUnit = webcastAd.adUnit,
      _webcastAd$targeting = webcastAd.targeting,
      targeting = _webcastAd$targeting === undefined ? {} : _webcastAd$targeting,
      networkID = webcastAd.networkID,
      _webcastAd$sizes = webcastAd.sizes,
      sizes = _webcastAd$sizes === undefined ? [[200, 100]] : _webcastAd$sizes;

  // AD targeting

  var adTargeting = {
    content_placement: targeting.content_placement,
    tags: targeting.tags,
    document_group: targeting.document_group,
    document_url: targeting.document_url,
    rootDocumentGroup: targeting.rootDocumentGroup,
    // setting pos for webcast ad.
    pos: 'smrec1',
    campaign_id: targeting.campaign_id,
    issue_url: targeting.issue_url,
    publication_url: targeting.publication_url
  };

  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      widthFlag = _useState2[0],
      setWidthFlag = _useState2[1];

  var _useState3 = useState(true),
      _useState4 = _slicedToArray(_useState3, 2);
      _useState4[0];
      var setPreviewAd = _useState4[1];

  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');
    }));
  }, []);

  useEffect(function () {
    if (window && window.innerWidth >= minScreenWidth) {
      setWidthFlag(true);
    }
  }, [minScreenWidth]);

  if (widthFlag) {
    return React.createElement(
      React.Fragment,
      null,
      React.createElement(
        'div',
        { id: 'webcast-ad-wrapper', className: 'webcast-ad-wrapper' },
        React.createElement(
          'div',
          { className: 'webcast-ad', style: { paddingBottom: '15px' } },
          React.createElement(DFPAdSlot, {
            className: className,
            slotId: slotId,
            networkID: networkID,
            sizes: sizes
            // To show AD from screenwidth >= 1200
            , sizeMapping: [{ viewport: [1200, 0], sizes: sizes }, { viewport: [0, 0], sizes: [0, 0] }],
            adUnit: adUnit,
            targeting: adTargeting
            /* Passing refresh flag */
            , refreshFlag: refreshFlag
            /* Passing function to check for ad creative only if it is not in preview. */
            // checkIsAdFound={previewAd ? null : checkIsAdFound}
          })
        ),
        React.createElement(
          'style',
          { jsx: 'true' },
          '\n            /* setting height to 0px when the ad slot is empty. */\n            .webcast-ad-wrapper div[id*=\'google_ads_iframe\']:empty {\n              height: 0px !important;\n            }\n          '
        )
      )
    );
  } else return null;
};

export default ADWebcast;
