import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-cedb5b78.js';
import './es6.string.iterator-1577cb76.js';
import './_library-528f1934.js';
import './_iter-detect-0fa1c752.js';
import './core.get-iterator-method-227107e6.js';
import './_object-pie-33c40e79.js';
import './extends-be71a29a.js';
import './web.dom.iterable-ace8ed30.js';
import React__default, { useState, useEffect } from 'react';
import './events-6c3a7a63.js';
import './index-41a678ea.js';
import 'prop-types';
import './isSymbol-1981418f.js';
import './debounce-89969f66.js';
import './toNumber-e3dcad26.js';
import './main-ae902629.js';
import { _ as _slicedToArray } from './slicedToArray-f0edf3d6.js';
import './stringify-d1b9276a.js';
import './asyncToGenerator-e1a2f43a.js';
import './Segment.js';
import './Beam.js';
import DFPAdSlot from './AdSlot.js';

var ADFloatingFooter = function ADFloatingFooter(_ref) {
  var title = _ref.title,
      floatingAd = _ref.floatingAd,
      minScreenWidth = _ref.minScreenWidth,
      _ref$refreshFlag = _ref.refreshFlag,
      refreshFlag = _ref$refreshFlag === undefined ? true : _ref$refreshFlag;
  var className = floatingAd.className,
      slotId = floatingAd.slotId,
      adUnit = floatingAd.adUnit,
      _floatingAd$targeting = floatingAd.targeting,
      targeting = _floatingAd$targeting === undefined ? {} : _floatingAd$targeting,
      _floatingAd$position = floatingAd.position,
      position = _floatingAd$position === undefined ? 'float' : _floatingAd$position,
      networkID = floatingAd.networkID;

  var adTargeting = {
    content_placement: targeting.content_placement,
    tags: targeting.tags,
    document_group: targeting.document_group,
    rootDocumentGroup: targeting.rootDocumentGroup,
    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];

  var _useState5 = useState(false),
      _useState6 = _slicedToArray(_useState5, 2),
      showAd = _useState6[0],
      setShowAd = _useState6[1];

  useEffect(function () {
    // Checking data in session storage to show AD
    if (!sessionStorage.getItem('mjh-floating-footer-ad')) setShowAd(true);
  }, []);

  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);
    }

    try {
      var _floatingAd = document.getElementById('floating-ad');
      var parent = document.getElementById('floating-ad-wrapper');
      if (_floatingAd.children[0].children.length === 0) {
        parent.classList.remove('display-floating');
        parent.classList.add('hide-floating');
      }
    } catch (e) {}
  }, [minScreenWidth]);

  var collapseAd = function collapseAd() {
    var parent = document.getElementById('floating-ad-wrapper');
    parent.style.height = '0%';
    parent.style.width = '0%';
    parent.classList.remove('display-floating');
    parent.classList.add('hide-floating');
    // Saving data in session storage on close AD
    sessionStorage.setItem('mjh-floating-footer-ad', Math.floor(Date.now() / 1000));
  };

  return React__default.createElement(
    React__default.Fragment,
    null,
    showAd && widthFlag && adTargeting.document_url && React__default.createElement(
      'div',
      { id: 'floating-ad-wrapper', className: 'floating-ad-wrapper display-floating ' + title },
      React__default.createElement(DFPAdSlot, {
        className: className,
        slotId: slotId,
        networkID: networkID,
        sizes: [[1025, 100]],
        adUnit: adUnit,
        targeting: adTargeting,
        refreshFlag: refreshFlag
        /* Passing function to check for ad creative only if it is not in preview. */
        // checkIsAdFound={previewAd ? null : checkIsAdFound}
      }),
      React__default.createElement(
        'div',
        { className: 'closeButton', onClick: function onClick() {
            return collapseAd();
          } },
        'x'
      )
    ),
    React__default.createElement(
      'style',
      { jsx: 'true' },
      '\n          .display-floating {\n            display: block;\n          }\n          .hide-floating {\n            display: none;\n          }\n          .floating-ad-wrapper {\n            margin: 0;\n            background-color: #f5f5f5;\n            position: fixed;\n            bottom: 0;\n            left: 50%;\n            transform: translateX(-50%);\n            z-index: 9000;\n          }\n          .closeButton {\n            position: absolute;\n            top: -16px;\n            right: -16px;\n            background: grey;\n            color: white;\n            font-weight: 500;\n            border: 2px solid white;\n            border-radius: 50%;\n            width: 30px;\n            height: 30px;\n            text-align: center;\n            font-size: 15px;\n            cursor: pointer;\n            z-index: 999999;\n          }\n          .floating-ad-wrapper div[id*=\'google_ads_iframe\']:empty {\n            height: 0px !important;\n          }\n        '
    )
  );
};

export default ADFloatingFooter;
