'use strict';

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

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 useBodyTTag = require('@prom-ui/core/useBodyTTag');
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 React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);

function ownKeys(object, enumerableOnly) {
  var keys = Object.keys(object);
  if (Object.getOwnPropertySymbols) {
    var symbols = Object.getOwnPropertySymbols(object);
    enumerableOnly && (symbols = symbols.filter(function (sym) {
      return Object.getOwnPropertyDescriptor(object, sym).enumerable;
    })), keys.push.apply(keys, symbols);
  }
  return keys;
}
function _objectSpread2(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = null != arguments[i] ? arguments[i] : {};
    i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
      _defineProperty(target, key, source[key]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
      Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
    });
  }
  return target;
}
function _defineProperty(obj, key, value) {
  key = _toPropertyKey(key);
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }
  return obj;
}
function _extends() {
  _extends = Object.assign ? Object.assign.bind() : function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
    return target;
  };
  return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;
  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }
  return target;
}
function _objectWithoutProperties(source, excluded) {
  if (source == null) return {};
  var target = _objectWithoutPropertiesLoose(source, excluded);
  var key, i;
  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i];
      if (excluded.indexOf(key) >= 0) continue;
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
      target[key] = source[key];
    }
  }
  return target;
}
function _taggedTemplateLiteral(strings, raw) {
  if (!raw) {
    raw = strings.slice(0);
  }
  return Object.freeze(Object.defineProperties(strings, {
    raw: {
      value: Object.freeze(raw)
    }
  }));
}
function _toPrimitive(input, hint) {
  if (typeof input !== "object" || input === null) return input;
  var prim = input[Symbol.toPrimitive];
  if (prim !== undefined) {
    var res = prim.call(input, hint || "default");
    if (typeof res !== "object") return res;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
  var key = _toPrimitive(arg, "string");
  return typeof key === "symbol" ? key : String(key);
}

var css = {"root":"Modal__root___LXzJW","closeButton":"Modal__closeButton___IfZSD","rootContent":"Modal__rootContent___p62nO","enter":"Modal__enter___CYsVE","exit":"Modal__exit___-sfQK","enterActive":"Modal__enterActive___Q3lip","exitActive":"Modal__exitActive___2XLH4"};

var _templateObject;
var _excluded = ["isOpen", "isRenderPortal", "isBodyScrollLock", "isShowCloseButton", "zIndex", "width", "height", "padding", "onClose", "className", "style", "children"];
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(_ref, _excluded);
  var _useBodyTTag = useBodyTTag.useBodyTTag(),
    t = _useBodyTTag.t;
  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, {
    "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", {
    className: css.root,
    role: "dialog",
    "aria-modal": true,
    "aria-labelledby": undefined,
    style: {
      zIndex: zIndex
    },
    onClick: onClickOutside,
    "data-qaid": 'modal' ,
    "data-testid": 'modal' 
  }, /*#__PURE__*/React__namespace.createElement("div", _extends({
    className: classNames__default.default(css.rootContent, className),
    style: _objectSpread2({
      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(["\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.css');
