'use strict';

var slicedToArray = require('./slicedToArray-067dd3bc.js');
var React = require('react');
require('./_commonjsHelpers-06173234.js');
require('./web.dom.iterable-d98303e0.js');
require('./core.get-iterator-method-5643aa10.js');

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

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

var ADFooter = function ADFooter(_ref) {
  var children = _ref.children;

  var _useState = React.useState(false),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      showAd = _useState2[0],
      setShowAd = _useState2[1];

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

  var handleCloseAd = function handleCloseAd() {
    setShowAd(false);
    // Saving data in session storage on close AD
    sessionStorage.setItem('mjh-floating-footer-ad', Math.floor(Date.now() / 1000));
  };

  return React__default["default"].createElement(
    React__default["default"].Fragment,
    null,
    showAd && React__default["default"].createElement(
      'div',
      { className: 'ADFooter' },
      children,
      React__default["default"].createElement(
        'div',
        { className: 'closeButton', onClick: handleCloseAd },
        'x'
      )
    ),
    React__default["default"].createElement(
      'style',
      { jsx: 'true' },
      '\n          .ADFooter {\n            width: auto;\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          .adBox > div:empty {\n            display: none !important;\n          }\n          .adBox > div:not(:empty) {\n            display: block !important;\n          }\n          .closeButton {\n            position: absolute;\n            top: -10px;\n            right: -10px;\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: 17px;\n            cursor: pointer;\n          }\n        '
    )
  );
};

module.exports = ADFooter;
