import { _ as _slicedToArray } from './slicedToArray-6ebcbfea.js';
import React__default, { useState, useEffect } from 'react';
import DFPAdSlot from './AdSlot.js';
import { d as main_22 } from './main-754d4992.js';
import './_commonjsHelpers-0c4b6f40.js';
import './web.dom.iterable-ab4dea5c.js';
import './core.get-iterator-method-ea258bb1.js';
import './extends-1559c147.js';
import 'prop-types';
import './index-f0fc23eb.js';
import './events-6c3a7a63.js';
import './debounce-533d9748.js';
import './isSymbol-a7e9aafe.js';
import './toNumber-5aeba6e7.js';
import './Beam.js';
import './stringify-2b084bee.js';
import './asyncToGenerator-64822ccc.js';
import './_library-528f1934.js';
import './_set-species-2cd9340f.js';
import './_iter-detect-98db3b07.js';
import './Segment.js';

// Skyscraper is below sponsored resource ad in the left column.
var ADSkyscraper = function ADSkyscraper(_ref) {
  var skyscraperAd = _ref.skyscraperAd,
      _ref$minScreenWidth = _ref.minScreenWidth,
      minScreenWidth = _ref$minScreenWidth === undefined ? 1200 : _ref$minScreenWidth,
      _ref$refreshFlag = _ref.refreshFlag,
      refreshFlag = _ref$refreshFlag === undefined ? false : _ref$refreshFlag;

  // position is set to 'sky1' as default.
  var className = skyscraperAd.className,
      slotId = skyscraperAd.slotId,
      adUnit = skyscraperAd.adUnit,
      _skyscraperAd$targeti = skyscraperAd.targeting,
      targeting = _skyscraperAd$targeti === undefined ? {} : _skyscraperAd$targeti,
      _skyscraperAd$positio = skyscraperAd.position,
      position = _skyscraperAd$positio === undefined ? 'sky1' : _skyscraperAd$positio,
      networkID = skyscraperAd.networkID,
      sizes = skyscraperAd.sizes;


  var adTargeting = {
    content_placement: targeting.content_placement,
    tags: targeting.tags,
    document_group: targeting.document_group,
    document_url: targeting.document_url,
    rootDocumentGroup: targeting.rootDocumentGroup,
    pos: position,
    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];

  var _useState5 = useState(refreshFlag),
      _useState6 = _slicedToArray(_useState5, 2),
      adRefreshFlag = _useState6[0],
      setAdRefreshFlag = _useState6[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');
    }));
    if (main_22.toLowerCase().indexOf('adwallet') >= 0) {
      setAdRefreshFlag(false);
    }
  }, []);

  useEffect(function () {
    // Setting flag to hide ad in screens < 1200px.
    if (window && window.innerWidth >= minScreenWidth) {
      setWidthFlag(true);
    }
  }, [minScreenWidth]);
  if (widthFlag) {
    return React__default.createElement(
      React__default.Fragment,
      null,
      React__default.createElement(
        'div',
        { id: 'skyscraper-ad-wrapper', className: 'skyscraper-ad-wrapper' },
        React__default.createElement(
          'div',
          { className: 'skyscraper-ad' },
          React__default.createElement(DFPAdSlot, {
            className: className,
            slotId: slotId,
            networkID: networkID,
            sizes: sizes,
            adUnit: adUnit,
            targeting: adTargeting
            /* Passing refresh flag */
            , refreshFlag: adRefreshFlag
            /* 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            .skyscraper-ad-wrapper {\n              margin-top: 20px;\n              margin-bottom: 20px;\n            }\n            .skyscraper-ad-wrapper div[id*=\'google_ads_iframe\']:empty {\n              height: 0px !important;\n            }\n          '
        )
      )
    );
  } else return null;
};

export { ADSkyscraper as default };
