'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

require('./_commonjsHelpers-06173234.js');
require('./_to-object-329a650b.js');
require('./es6.string.iterator-cc0bbaa4.js');
require('./_library-dd23b178.js');
require('./_iter-detect-60b2f026.js');
require('./core.get-iterator-method-f62321d4.js');
require('./_object-pie-68c5bcbc.js');
require('./extends-0a918631.js');
require('./web.dom.iterable-a0e279c1.js');
var React = require('react');
var React__default = _interopDefault(React);
require('./events-1b438fe7.js');
require('./index-98e01cb9.js');
require('prop-types');
require('./isSymbol-04666465.js');
require('./debounce-529c8d06.js');
require('./toNumber-36d1e7e5.js');
require('./main-02daeefe.js');
var slicedToArray = require('./slicedToArray-8f385299.js');
require('./stringify-7c5aff47.js');
require('./asyncToGenerator-140e5f89.js');
require('./Segment.js');
require('./Beam.js');
var AdSlot = require('./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,
      _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 = React.useState(false),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      widthFlag = _useState2[0],
      setWidthFlag = _useState2[1];

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

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

  React.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(AdSlot, {
            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            .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;
};

module.exports = ADSkyscraper;
