"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _bem = require("@zarm-design/bem");

var _isFinite = _interopRequireDefault(require("lodash/isFinite"));

var React = _interopRequireWildcard(require("react"));

var _configProvider = require("../config-provider");

var _transition = _interopRequireDefault(require("../transition"));

var _dom = require("../utils/dom");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var OpacityList = {
  normal: 0.55,
  light: 0.35,
  dark: 0.75
};
var Mask = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var className = props.className,
      style = props.style,
      visible = props.visible,
      color = props.color,
      opacity = props.opacity,
      animationDuration = props.animationDuration,
      forceRender = props.forceRender,
      destroy = props.destroy,
      afterOpen = props.afterOpen,
      afterClose = props.afterClose,
      onClick = props.onClick,
      children = props.children,
      mountContainer = props.mountContainer;

  var _React$useContext = React.useContext(_configProvider.ConfigContext),
      prefixCls = _React$useContext.prefixCls,
      globalMountContainer = _React$useContext.mountContainer;

  var bem = (0, _bem.createBEM)('mask', {
    prefixCls: prefixCls
  });
  var rgb = color === 'black' ? '0, 0, 0' : '255, 255, 255';
  var backgroundOpacity = (0, _isFinite.default)(opacity) ? opacity : OpacityList[opacity];
  return /*#__PURE__*/React.createElement(_transition.default, {
    nodeRef: ref,
    visible: visible,
    tranisitionName: "".concat(prefixCls, "-fade"),
    duration: animationDuration,
    forceRender: forceRender,
    destroy: destroy,
    onEnter: function onEnter() {
      afterOpen === null || afterOpen === void 0 ? void 0 : afterOpen();
    },
    onLeaveEnd: function onLeaveEnd() {
      afterClose === null || afterClose === void 0 ? void 0 : afterClose();
    }
  }, function (rest, setNodeRef) {
    return (0, _dom.renderToContainer)(mountContainer !== null && mountContainer !== void 0 ? mountContainer : globalMountContainer, /*#__PURE__*/React.createElement("div", {
      ref: setNodeRef,
      className: bem([className, rest.className]),
      style: _objectSpread(_objectSpread(_objectSpread({}, style), rest.style), {}, {
        backgroundColor: color === 'transparent' ? 'transparent' : "rgba(".concat(rgb, ", ").concat(backgroundOpacity, ")")
      }),
      onClick: onClick
    }, children));
  });
});
Mask.displayName = 'Mask';
Mask.defaultProps = {
  visible: false,
  color: 'black',
  opacity: 'normal'
};
var _default = Mask;
exports.default = _default;