'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _extends = require('@babel/runtime/helpers/extends');
var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var reactTransitionGroup = require('react-transition-group');
var classNames = require('clsx');
var Backdrop = require('@prom-ui/core/Backdrop');
var Button = require('@prom-ui/core/Button');
var Icon = require('@prom-ui/core/Icon');
var KeyPress = require('@prom-ui/core/KeyPress');
var Portal = require('@prom-ui/core/Portal');
var BodyProvider = require('@prom-ui/core/BodyProvider');
var Close2 = require('@prom-ui/icons/Close2');

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

function _interopNamespaceCompat(e) {
    if (e && typeof e === 'object' && 'default' in e) return e;
    var n = Object.create(null);
    if (e) {
        Object.keys(e).forEach(function (k) {
            if (k !== 'default') {
                var d = Object.getOwnPropertyDescriptor(e, k);
                Object.defineProperty(n, k, d.get ? d : {
                    enumerable: true,
                    get: function () { return e[k]; }
                });
            }
        });
    }
    n.default = e;
    return Object.freeze(n);
}

var _extends__default = /*#__PURE__*/_interopDefaultCompat(_extends);
var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultCompat(_taggedTemplateLiteral);
var _defineProperty__default = /*#__PURE__*/_interopDefaultCompat(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultCompat(_objectWithoutProperties);
var React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);

var css = {"root":"Modal__root___9vQ1b","closeButton":"Modal__closeButton___5HA1l","rootContent":"Modal__rootContent___OXp7s","enter":"Modal__enter___JQ0Kx","exit":"Modal__exit___llwRD","enterActive":"Modal__enterActive___p-g77","exitActive":"Modal__exitActive___mioMB"};

var _templateObject;
var _excluded = ["isOpen", "isRenderPortal", "isBodyScrollLock", "isShowCloseButton", "zIndex", "width", "height", "padding", "onClose", "className", "style", "children"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Modal = function Modal(_ref) {
  var _ref$isOpen = _ref.isOpen,
    isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen,
    _ref$isRenderPortal = _ref.isRenderPortal,
    isRenderPortal = _ref$isRenderPortal === void 0 ? true : _ref$isRenderPortal,
    _ref$isBodyScrollLock = _ref.isBodyScrollLock,
    isBodyScrollLock = _ref$isBodyScrollLock === void 0 ? true : _ref$isBodyScrollLock,
    _ref$isShowCloseButto = _ref.isShowCloseButton,
    isShowCloseButton = _ref$isShowCloseButto === void 0 ? true : _ref$isShowCloseButto,
    _ref$zIndex = _ref.zIndex,
    zIndex = _ref$zIndex === void 0 ? 5000 : _ref$zIndex,
    _ref$width = _ref.width,
    width = _ref$width === void 0 ? 'auto' : _ref$width,
    _ref$height = _ref.height,
    height = _ref$height === void 0 ? 'auto' : _ref$height,
    _ref$padding = _ref.padding,
    padding = _ref$padding === void 0 ? 36 : _ref$padding,
    onClose = _ref.onClose,
    className = _ref.className,
    style = _ref.style,
    children = _ref.children,
    props = _objectWithoutProperties__default.default(_ref, _excluded);
  var _useBodyStoreTTag = BodyProvider.useBodyStoreTTag(),
    t = _useBodyStoreTTag.t;
  var nodeRef = React__namespace.useRef(null);
  var onClickOutside = function onClickOutside(e) {
    if (e.target === e.currentTarget) {
      onClose(e);
    }
  };
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(Backdrop.Backdrop, {
    isOpen: isOpen,
    zIndex: zIndex,
    isRenderPortal: isRenderPortal,
    isBodyScrollLock: isBodyScrollLock
  }), /*#__PURE__*/React__namespace.createElement(reactTransitionGroup.CSSTransition, {
    nodeRef: nodeRef,
    "in": isOpen,
    timeout: 240,
    classNames: css,
    unmountOnExit: true
  }, /*#__PURE__*/React__namespace.createElement(Portal.Portal, {
    isActive: isRenderPortal
  }, /*#__PURE__*/React__namespace.createElement(KeyPress.KeyPress, {
    code: "Escape",
    onKeyDown: onClose
  }), /*#__PURE__*/React__namespace.createElement("div", {
    ref: nodeRef,
    className: css.root,
    role: "dialog",
    "aria-modal": true,
    "aria-labelledby": undefined,
    style: {
      zIndex: zIndex
    },
    onClick: onClickOutside,
    "data-qaid": props['data-qaid'] || 'modal',
    "data-testid": props['data-testid'] || 'modal'
  }, /*#__PURE__*/React__namespace.createElement("div", _extends__default.default({
    className: classNames__default.default(css.rootContent, className),
    style: _objectSpread({
      width: width,
      height: height,
      padding: padding
    }, style)
  }, props, {
    "data-qaid": "modal_content",
    "data-testid": "modal_content"
  }), children, isShowCloseButton && /*#__PURE__*/React__namespace.createElement("div", {
    className: css.closeButton
  }, /*#__PURE__*/React__namespace.createElement(Button.Button, {
    "button-theme": "black-inherit",
    "button-padding": "xxs",
    type: "button",
    onClick: onClose,
    "aria-label": t(_templateObject || (_templateObject = _taggedTemplateLiteral__default.default(["\u0417\u0430\u043A\u0440\u044B\u0442\u044C"]))),
    "data-qaid": "modal_close_button",
    "data-testid": "modal_close_button"
  }, /*#__PURE__*/React__namespace.createElement(Icon.Icon, {
    "icon-as": Close2.SvgClose2,
    style: {
      width: 24,
      height: 24
    }
  }))))))));
};
Modal.displayName = 'Modal';

exports.Modal = Modal;

require('./style.development.v2.css');
