import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-ded78eb9.js';
import './es6.string.iterator-9b2af4a5.js';
import './_library-528f1934.js';
import './_iter-detect-59409a32.js';
import './core.get-iterator-method-54d2e411.js';
import './web.dom.iterable-8956f9a5.js';
import React__default, { useState, useEffect } from 'react';
import './index-0e45a0b2.js';
import 'prop-types';
import './isSymbol-807e927e.js';
import './debounce-1a993acf.js';
import './main-5d1e4bd3.js';
import { _ as _JSON$stringify } from './stringify-008c8802.js';
import { _ as _slicedToArray } from './slicedToArray-7021e5df.js';
import './asyncToGenerator-7c654f36.js';
import './_set-species-cede29f8.js';
import './Segment.js';
import './Beam.js';
import DFPAdSlot from './AdSlot.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;

  // 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,
    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),
      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 () {
    // Setting flag to hide ad in screens < 1200px.
    if (window && window.innerWidth >= minScreenWidth) {
      setWidthFlag(true);
    }
  }, [minScreenWidth]);

  // Function to collapse skyscrapper ad.
  var collapseAd = function collapseAd() {
    var parent = document.getElementById('skyscraper-ad-wrapper');
    parent.style.height = '0%';
    parent.style.width = '0%';
    parent.style.display = 'none';
  };

  // Function to check if the skyscrapper ad is available or not.
  var checkIsAdFound = function checkIsAdFound(isFound, adData) {
    if (isFound) {
      var parent = document.getElementById('skyscraper-ad-wrapper');

      var adSizes = [[1, 1]];
      // Collapsing ad if the as size is [1,1]
      if (adData && adData.event && adData.event.size) {
        var checkAdSize = function checkAdSize(size) {
          return _JSON$stringify(size) === _JSON$stringify(adData.event.size);
        };

        if (adSizes.some(checkAdSize)) {
          // collapsing skyscrapper AD.
          collapseAd();
          parent.style.display = 'none';
        } else {
          parent.style.display = 'block';
        }
      }
    } else {
      collapseAd();
    }
  };
  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,
            refreshFlag: false
            /* 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 default ADSkyscraper;
