import { _ as _slicedToArray } from './slicedToArray-be2f7a22.js';
import React, { useState, useEffect } from 'react';
import DFPAdSlot from './AdSlot.js';
import './_commonjsHelpers-0c4b6f40.js';
import './web.dom.iterable-4109ff68.js';
import './es6.string.iterator-bc33758b.js';
import './_to-object-b50e61c3.js';
import './core.get-iterator-method-133dfacd.js';
import './extends-60e0e1c6.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-59c8f690.js';
import './asyncToGenerator-7f8f9219.js';
import './_library-528f1934.js';
import './_iter-detect-7e5e5ce2.js';
import './Segment.js';
import './main-b5c5aac1.js';

var ADGutter = function ADGutter(_ref) {
  var title = _ref.title,
      gutterAd = _ref.gutterAd,
      _ref$minScreenWidth = _ref.minScreenWidth,
      minScreenWidth = _ref$minScreenWidth === undefined ? 1700 : _ref$minScreenWidth,
      _ref$refreshFlag = _ref.refreshFlag,
      refreshFlag = _ref$refreshFlag === undefined ? false : _ref$refreshFlag;
  var className = gutterAd.className,
      slotId = gutterAd.slotId,
      adUnit = gutterAd.adUnit,
      _gutterAd$targeting = gutterAd.targeting,
      targeting = _gutterAd$targeting === undefined ? {} : _gutterAd$targeting,
      _gutterAd$position = gutterAd.position,
      position = _gutterAd$position === undefined ? 'wallpaper' : _gutterAd$position,
      networkID = gutterAd.networkID,
      sizes = gutterAd.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];

  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,
      widthFlag && React.createElement(
        'div',
        { id: 'gutter-ad-wrapper', className: 'gutter-ad-wrapper ' + title },
        React.createElement(
          'div',
          { className: 'gutter-ad' },
          React.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.createElement(
        'style',
        { jsx: 'true' },
        '\n          .gutter-ad-wrapper {\n            position: fixed;\n            width: 100%;\n            height: 100%;\n            z-index: 999;\n          }\n          .gutter-ad {\n            width: 150px;\n            position: relative;\n            top: 50;\n          }\n          /* setting height to 0px when the ad slot is empty. */\n          .gutter-ad-wrapper div[id*=\'google_ads_iframe\']:empty {\n            height: 0px !important;\n          }\n        '
      )
    );
  } else return null;
};

export default ADGutter;
