var _excluded = ["portal", "maskClosable", "maskProps", "visible", "onVisibleChange", "animation", "children"];
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 _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 _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; }
import React, { useImperativeHandle, forwardRef, useRef } from 'react';
import { createPortal } from 'react-dom';

// 内库使用-start
import getClassNameByAnimation from "./../../Modal/api/getClassNameByAnimation";
import DOMUtil from "./../../../utils/DOMUtil";
// 内库使用-end

/* 测试使用-start
import { DOMUtil, Modal } from 'seedsui-react'
const getClassNameByAnimation = Modal.getClassNameByAnimation
测试使用-end */

// 对话框
var Confirm = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var portal = _ref.portal,
    maskClosable = _ref.maskClosable,
    maskProps = _ref.maskProps,
    visible = _ref.visible,
    onVisibleChange = _ref.onVisibleChange,
    _ref$animation = _ref.animation,
    animation = _ref$animation === void 0 ? 'zoom' : _ref$animation,
    children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded);
  var maskRef = useRef(null);
  var modalRef = useRef(null);

  // Expose
  useImperativeHandle(ref, function () {
    return {
      maskDOM: maskRef.current,
      getMaskDOM: function getMaskDOM() {
        return maskRef.current;
      },
      modalDOM: modalRef.current,
      getModalDOM: function getModalDOM() {
        return modalRef.current;
      }
    };
  });

  // 点击遮罩
  function handleMaskClick(e) {
    if (maskProps !== null && maskProps !== void 0 && maskProps.onClick) maskProps.onClick(e);
    if (maskClosable && onVisibleChange) onVisibleChange(false);
    e.stopPropagation();
  }

  // 点击模态框
  function handleModalClick(e) {
    e.stopPropagation();
  }

  // 获取激活状态样式
  function getActiveClass() {
    return visible ? ' active' : '';
  }
  return /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", _extends({}, maskProps, {
    className: DOMUtil.classNames('mask confirm-mask', maskProps === null || maskProps === void 0 ? void 0 : maskProps.className, getActiveClass()),
    onClick: handleMaskClick,
    ref: maskRef
  }), /*#__PURE__*/React.createElement("section", _extends({}, props, {
    className: DOMUtil.classNames('modal-animation confirm-modal', props.className, getClassNameByAnimation(animation), getActiveClass()),
    "data-animation": animation,
    ref: modalRef,
    onClick: handleModalClick
  }), children)), portal || document.getElementById('root') || document.body);
});
export default Confirm;