'use strict';

require('./_commonjsHelpers-06173234.js');
require('./core.get-iterator-method-f3c44602.js');
require('./_library-dd23b178.js');
require('./_iter-detect-05795553.js');
require('./_object-pie-68c5bcbc.js');
require('./extends-7df78678.js');
require('./web.dom.iterable-e34bf324.js');
var React = require('react');
require('./index-44481153.js');
require('prop-types');
require('./isSymbol-04666465.js');
require('./debounce-529c8d06.js');
require('./toNumber-36d1e7e5.js');
var slicedToArray = require('./slicedToArray-f6d4eaa8.js');
require('./main-7b5e57b0.js');
require('./stringify-bbc68047.js');
require('./asyncToGenerator-df19209d.js');
require('./Segment.js');
require('./Beam.js');
var AdSlot = require('./AdSlot.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

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 = 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 () {
    if (window && window.innerWidth >= minScreenWidth) {
      setWidthFlag(true);
    }
  }, [minScreenWidth]);

  if (widthFlag) {
    return React__default['default'].createElement(
      React__default['default'].Fragment,
      null,
      widthFlag && React__default['default'].createElement(
        'div',
        { id: 'gutter-ad-wrapper', className: 'gutter-ad-wrapper ' + title },
        React__default['default'].createElement(
          'div',
          { className: 'gutter-ad' },
          React__default['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['default'].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;
};

module.exports = ADGutter;
