import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-a4107da3.js';
import './es6.string.iterator-c990c18c.js';
import './_library-528f1934.js';
import './_iter-detect-5d49a330.js';
import './core.get-iterator-method-e1de7503.js';
import './_object-pie-33c40e79.js';
import './extends-eb69e8ac.js';
import './web.dom.iterable-4439f05a.js';
import React__default, { useState, useEffect } from 'react';
import './index-a9e53f80.js';
import 'prop-types';
import './isSymbol-807e927e.js';
import './debounce-1a993acf.js';
import './main-e4a934b2.js';
import { _ as _slicedToArray } from './slicedToArray-641f241f.js';
import './stringify-4330ccdc.js';
import './asyncToGenerator-502f13b4.js';
import './_set-species-3f8319f5.js';
import './Segment.js';
import './Beam.js';
import DFPAdSlot from './AdSlot.js';

var ADSponsoredResources = function ADSponsoredResources(_ref) {
  var sponsoredAd = _ref.sponsoredAd,
      _ref$minScreenWidth = _ref.minScreenWidth,
      minScreenWidth = _ref$minScreenWidth === undefined ? 1200 : _ref$minScreenWidth,
      _ref$refreshFlag = _ref.refreshFlag,
      refreshFlag = _ref$refreshFlag === undefined ? false : _ref$refreshFlag;
  var className = sponsoredAd.className,
      slotId = sponsoredAd.slotId,
      adUnit = sponsoredAd.adUnit,
      _sponsoredAd$targetin = sponsoredAd.targeting,
      targeting = _sponsoredAd$targetin === undefined ? {} : _sponsoredAd$targetin,
      _sponsoredAd$position = sponsoredAd.position,
      position = _sponsoredAd$position === undefined ? 'sponsor' : _sponsoredAd$position,
      networkID = sponsoredAd.networkID,
      sizes = sponsoredAd.sizes;


  var adTargeting = {
    content_placement: targeting.content_placement,
    tags: targeting.tags,
    document_group: targeting.document_group,
    document_url: targeting.document_url,
    pos: position,
    rootDocumentGroup: targeting.rootDocumentGroup,
    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),
      previewAd = _useState4[0],
      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__default.createElement(
      React__default.Fragment,
      null,
      React__default.createElement(
        'div',
        { id: 'sponsored-ad-wrapper', className: 'sponsored-ad-wrapper' },
        React__default.createElement(
          'div',
          { className: 'sponsored-ad' },
          React__default.createElement(DFPAdSlot, {
            className: className,
            slotId: slotId,
            networkID: networkID,
            sizes: sizes,
            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__default.createElement(
          'style',
          { jsx: 'true' },
          '\n            /* setting height to 0px when the ad slot is empty. */\n            .sponsored-ad-wrapper div[id*=\'google_ads_iframe\']:empty {\n              height: 0px !important;\n            }\n          '
        )
      )
    );
  } else return null;
};

export default ADSponsoredResources;
