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 { m as main_36 } from './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';

var AD728x90 = function AD728x90(_ref) {
  var networkID = _ref.networkID,
      adUnit = _ref.adUnit,
      _ref$slotId = _ref.slotId,
      slotId = _ref$slotId === undefined ? 'leaderboard-ad' : _ref$slotId,
      _ref$targeting = _ref.targeting,
      targeting = _ref$targeting === undefined ? {} : _ref$targeting,
      _ref$pos = _ref.pos,
      pos = _ref$pos === undefined ? 'top' : _ref$pos,
      _ref$fixedPos = _ref.fixedPos;

  var mobileView = false;
  if (main_36) {
    pos = 'top-mobile';
    mobileView = true;
  }

  var _useState = useState(true),
      _useState2 = _slicedToArray(_useState, 2),
      previewAd = _useState2[0],
      setPreviewAd = _useState2[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');
    }));
  }, []);

  var adTargeting = {
    content_placement: targeting.content_placement,
    tags: targeting.tags,
    document_group: targeting.document_group,
    document_url: targeting.document_url,
    pos: pos,
    campaign_id: targeting.campaign_id,
    issue_url: targeting.issue_url,
    publication_url: targeting.publication_url
  };

  var browserSizes = [[728, 90], [970, 90], [320, 50], [300, 50]];
  var mobileSizes = [[320, 50], [300, 50]];

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

  // CallBack function to check if ad has got creative or not.
  var checkIsAdFound = function checkIsAdFound(isFound, adData) {
    if (isFound) {
      // Dynamically fetching parent from slotID to display or collapse.
      var parent = document.getElementById(adData.slotId);
      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)) {
          // passing slotID to collape
          collapseAd(adData.slotId);
          parent.style.display = 'none';
        } else {
          parent.style.display = 'block';
        }
      }
    } else {
      // collapsing ad if no creative is found
      collapseAd(adData.slotId);
    }
  };

  return React__default.createElement(
    'div',
    { className: 'leaderboard-ad-wrapper' },
    React__default.createElement(DFPAdSlot, {
      slotId: slotId,
      networkID: networkID,
      adUnit: adUnit,
      targeting: adTargeting,
      className: 'AD728x90',
      sizes: mobileView ? mobileSizes : browserSizes,
      sizeMapping: [{
        viewport: [768, 1],
        sizes: [[728, 90], [970, 90]]
      }, {
        viewport: [1, 1],
        sizes: [[320, 50], [300, 50]]
      }]
      /* 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        .leaderboard-ad-wrapper {\n          height: auto !important;\n          background: #fff;\n        }\n        .leaderboard-ad-wrapper .AD728x90 {\n          height: auto !important;\n        }\n        /* setting height to 0px when the ad slot is empty. */\n        .leaderboard-ad-wrapper .AD728x90 div[id*=\'google_ads_iframe\']:empty {\n          height: 0px !important;\n        }\n      '
    ),
    main_36 && React__default.createElement(
      'style',
      { jsx: 'true' },
      '\n          @media screen and (max-width: 768px) {\n            .leaderboard-ad-wrapper {\n              min-height: 0px;\n              position: fixed;\n              background: transparent;\n              background-color: transparent;\n              bottom: 0px;\n              left: 50%;\n              transform: translateX(-50%);\n              z-index: 9999;\n            }\n          }\n        '
    )
  );
};

export default AD728x90;
