"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _modal = _interopRequireDefault(require("../modal"));
var _configProvider = _interopRequireDefault(require("../config-provider"));
var _ActionButton = _interopRequireDefault(require("./ActionButton"));
var _index = _interopRequireDefault(require("./index"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const ConfirmDialog = props => {
  const {
    icon,
    onCancel,
    onOk,
    close,
    zIndex,
    afterClose,
    visible,
    open = visible,
    keyboard,
    centered = true,
    getContainer,
    maskStyle,
    okText,
    okButtonProps,
    cancelText,
    cancelButtonProps,
    direction,
    prefixCls,
    rootPrefixCls,
    bodyStyle,
    closable = true,
    closeIcon,
    modalRender,
    title,
    focusTriggerAfterClose
  } = props;

  // 支持传入{ icon: null }来隐藏`Modal.confirm`默认的Icon
  const okType = props.okType || 'primary';
  const contentPrefixCls = `${prefixCls}-confirm`;
  // 默认为 true，保持向下兼容
  const okCancel = 'okCancel' in props ? props.okCancel : true;
  const width = props.width || 416;
  const style = props.style || {};
  const mask = props.mask === undefined ? true : props.mask;
  // 默认为 false，保持旧版默认行为
  const maskClosable = props.maskClosable === undefined ? false : props.maskClosable;
  const autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok';
  const classString = (0, _classnames.default)(contentPrefixCls, `${contentPrefixCls}-${props.type}`, {
    [`${contentPrefixCls}-rtl`]: direction === 'rtl'
  }, 'wii-modal-confirm', props.className);
  const cancelButton = okCancel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton.default, {
    actionFn: onCancel,
    closeModal: close,
    autoFocus: autoFocusButton === 'cancel',
    buttonProps: cancelButtonProps,
    prefixCls: `${rootPrefixCls}-btn`,
    children: cancelText
  });
  (0, _react.useEffect)(() => {
    _index.default.raven.send(_index.default.RAVEN_MESSAGE_NAME, {
      visible: open
    });
  }, [open]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_modal.default, {
    prefixCls: prefixCls,
    className: classString,
    wrapClassName: (0, _classnames.default)({
      [`${contentPrefixCls}-centered`]: !!props.centered
    }),
    onCancel: () => close({
      triggerCancel: true
    }),
    open: open,
    title: title,
    footer: null,
    mask: mask,
    maskClosable: maskClosable,
    maskStyle: maskStyle,
    style: style,
    width: width,
    zIndex: zIndex,
    afterClose: afterClose,
    keyboard: keyboard,
    centered: centered,
    getContainer: getContainer,
    closable: closable,
    closeIcon: closeIcon,
    modalRender: modalRender,
    focusTriggerAfterClose: focusTriggerAfterClose,
    bodyStyle: {
      paddingTop: title ? 0 : 24
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: `${contentPrefixCls}-body-wrapper`,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.default, {
        prefixCls: rootPrefixCls,
        children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
          className: `${contentPrefixCls}-body`,
          style: bodyStyle,
          children: [icon, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: `${contentPrefixCls}-content`,
            children: props.content
          })]
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: `${contentPrefixCls}-btns`,
        children: [cancelButton, /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton.default, {
          type: okType,
          actionFn: onOk,
          closeModal: close,
          autoFocus: autoFocusButton === 'ok',
          buttonProps: okButtonProps,
          prefixCls: `${rootPrefixCls}-btn`,
          children: okText
        })]
      })]
    })
  });
};
var _default = ConfirmDialog;
exports.default = _default;