import React, { useEffect } from 'react';
import classNames from 'classnames';
import Dialog from '../modal';
import ConfigProvider from '../config-provider';
import ActionButton from './ActionButton';
import WauModal from './index';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
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 = classNames(contentPrefixCls, `${contentPrefixCls}-${props.type}`, {
    [`${contentPrefixCls}-rtl`]: direction === 'rtl'
  }, 'wii-modal-confirm', props.className);
  const cancelButton = okCancel && /*#__PURE__*/_jsx(ActionButton, {
    actionFn: onCancel,
    closeModal: close,
    autoFocus: autoFocusButton === 'cancel',
    buttonProps: cancelButtonProps,
    prefixCls: `${rootPrefixCls}-btn`,
    children: cancelText
  });
  useEffect(() => {
    WauModal.raven.send(WauModal.RAVEN_MESSAGE_NAME, {
      visible: open
    });
  }, [open]);
  return /*#__PURE__*/_jsx(Dialog, {
    prefixCls: prefixCls,
    className: classString,
    wrapClassName: classNames({
      [`${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__*/_jsxs("div", {
      className: `${contentPrefixCls}-body-wrapper`,
      children: [/*#__PURE__*/_jsx(ConfigProvider, {
        prefixCls: rootPrefixCls,
        children: /*#__PURE__*/_jsxs("div", {
          className: `${contentPrefixCls}-body`,
          style: bodyStyle,
          children: [icon, /*#__PURE__*/_jsx("div", {
            className: `${contentPrefixCls}-content`,
            children: props.content
          })]
        })
      }), /*#__PURE__*/_jsxs("div", {
        className: `${contentPrefixCls}-btns`,
        children: [cancelButton, /*#__PURE__*/_jsx(ActionButton, {
          type: okType,
          actionFn: onOk,
          closeModal: close,
          autoFocus: autoFocusButton === 'ok',
          buttonProps: okButtonProps,
          prefixCls: `${rootPrefixCls}-btn`,
          children: okText
        })]
      })]
    })
  });
};
export default ConfirmDialog;