'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

require('./_commonjsHelpers-06173234.js');
require('./_to-object-329a650b.js');
require('./es6.string.iterator-cc0bbaa4.js');
require('./_library-dd23b178.js');
require('./_iter-detect-60b2f026.js');
require('./core.get-iterator-method-f62321d4.js');
require('./_object-pie-68c5bcbc.js');
require('./extends-0a918631.js');
require('./web.dom.iterable-a0e279c1.js');
var React = require('react');
var React__default = _interopDefault(React);
require('./events-1b438fe7.js');
require('./index-98e01cb9.js');
require('prop-types');
require('./isSymbol-04666465.js');
require('./debounce-529c8d06.js');
require('./toNumber-36d1e7e5.js');
require('./main-02daeefe.js');
var slicedToArray = require('./slicedToArray-8f385299.js');
require('./stringify-7c5aff47.js');
require('./asyncToGenerator-140e5f89.js');
require('./Segment.js');
require('./Beam.js');
var AdSlot = require('./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 = React.useState(null),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      timeLeft = _useState2[0],
      setTimeLeft = _useState2[1];

  React.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(AdSlot, {
          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      '
      )
    )
  );
};

module.exports = ADWelcome;
