import _defineProperty from "@babel/runtime/helpers/defineProperty";

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) { _defineProperty(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; }

import { createBEM } from '@zarm-design/bem';
import isFinite from 'lodash/isFinite';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import Transition from '../transition';
import { renderToContainer } from '../utils/dom';
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(ConfigContext),
      prefixCls = _React$useContext.prefixCls,
      globalMountContainer = _React$useContext.mountContainer;

  var bem = createBEM('mask', {
    prefixCls: prefixCls
  });
  var rgb = color === 'black' ? '0, 0, 0' : '255, 255, 255';
  var backgroundOpacity = isFinite(opacity) ? opacity : OpacityList[opacity];
  return /*#__PURE__*/React.createElement(Transition, {
    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 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'
};
export default Mask;