import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-a4107da3.js';
import './es6.string.iterator-c990c18c.js';
import './_library-528f1934.js';
import './_iter-detect-5d49a330.js';
import './core.get-iterator-method-e1de7503.js';
import './_object-pie-33c40e79.js';
import './extends-eb69e8ac.js';
import './web.dom.iterable-4439f05a.js';
import React__default, { useState, useEffect } from 'react';
import './index-a9e53f80.js';
import 'prop-types';
import './isSymbol-807e927e.js';
import './debounce-1a993acf.js';
import './main-e4a934b2.js';
import { _ as _slicedToArray } from './slicedToArray-641f241f.js';
import './stringify-4330ccdc.js';
import './asyncToGenerator-502f13b4.js';
import './_set-species-3f8319f5.js';
import './Segment.js';
import './Beam.js';
import DFPAdSlot from './AdSlot.js';

var ADWelcome = function ADWelcome(_ref) {
  var title = _ref.title,
      welcomeAd = _ref.welcomeAd,
      setFlag = _ref.setFlag,
      Website = _ref.Website,
      counter = _ref.counter;
  var className = welcomeAd.className,
      slotId = welcomeAd.slotId,
      adUnit = welcomeAd.adUnit,
      _welcomeAd$targeting = welcomeAd.targeting,
      targeting = _welcomeAd$targeting === undefined ? {} : _welcomeAd$targeting,
      _welcomeAd$position = welcomeAd.position,
      position = _welcomeAd$position === undefined ? 'welcome' : _welcomeAd$position,
      networkID = welcomeAd.networkID,
      sizes = welcomeAd.sizes;

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

  var calculateTimeLeft = function calculateTimeLeft(timeLeft) {
    return --timeLeft;
  };

  var _useState = useState(null),
      _useState2 = _slicedToArray(_useState, 2),
      timeLeft = _useState2[0],
      setTimeLeft = _useState2[1];

  useEffect(function () {
    if (timeLeft !== null) {
      if (timeLeft > 0) {
        setTimeout(function () {
          setTimeLeft(calculateTimeLeft(timeLeft));
        }, 1000);
      } else {
        document.body.style.overflow = 'auto';
        setFlag(true);
      }
    }
  }, [timeLeft]);

  var checkIsAdFound = function checkIsAdFound(isFound, adData) {
    if (isFound) {
      var parent = document.getElementById('welcome-modal');
      document.body.style.overflow = 'hidden';
      parent.style.display = 'block';
      parent.style.opacity = '1';
      setTimeLeft(counter);
    } else {
      document.body.style.overflow = 'auto';
      setFlag(true);
    }
  };

  return (
    // Setting welcome ad to display:none and Setting to display:block after checking for cookie in site level.
    React__default.createElement(
      'div',
      { style: { outline: 'none', display: 'none' }, className: 'welcome-modal', id: 'welcome-modal' },
      React__default.createElement(
        'div',
        { className: 'welcome-ad-head-wrapper' },
        React__default.createElement(
          'div',
          { className: 'left-top' },
          React__default.createElement('img', { style: { width: '100%' }, src: Website.logo, alt: Website.title })
        ),
        React__default.createElement(
          'div',
          { className: 'right-top' },
          React__default.createElement(
            'span',
            {
              className: 'continue-site',
              style: {
                fontSize: '1.2rem',
                fontWeight: 'bold',
                fontFamily: "'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'"
              },
              onClick: function onClick() {
                document.body.style.overflow = 'auto';
                setFlag(true);
              } },
            'CONTINUE TO SITE'
          ),
          React__default.createElement(
            'p',
            {
              style: {
                fontSize: '0.8rem',
                fontFamily: "'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'"
              },
              className: 'timer-block' },
            'OR WAIT ' + timeLeft + ' SECS'
          )
        )
      ),
      React__default.createElement(
        'div',
        { className: title },
        React__default.createElement(DFPAdSlot, {
          className: className,
          slotId: slotId,
          networkID: networkID,
          sizes: sizes,
          adUnit: adUnit,
          targeting: adTargeting,
          refreshFlag: false,
          checkIsAdFound: checkIsAdFound
        })
      ),
      React__default.createElement(
        'style',
        { jsx: 'true' },
        '\n        .continue-site:hover {\n          cursor: pointer;\n        }\n\n        .welcome-modal {\n          max-width: 100% !important;\n          margin: 0px !important;\n          height: 100vh;\n        }\n        .welcome-ad-head-wrapper {\n          display: flex;\n          justify-content: space-between;\n        }\n        .right-top {\n          max-width: 250px;\n          padding: 10px;\n        }\n        .left-top {\n          max-width: 250px;\n          padding: 10px;\n        }\n        .' + title + ' {\n          width: auto !important;\n          padding-top: 25px;\n          justify-content: center;\n          align-items: center;\n          display: flex;\n        }\n        /* setting height to 0px when the ad slot is empty. */\n        .' + title + ' div[id*=\'google_ads_iframe\']:empty {\n          height: 0px !important;\n        }\n      '
      )
    )
  );
};

export default ADWelcome;
