import { _ as _slicedToArray } from '../_verture/slicedToArray-76060636.js';
import { _ as __rest } from '../_verture/tslib.es6-55ed4bd2.js';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import React__default, { useState, useEffect } from 'react';
import CompleteIcon from '@iam-com/icons/CheckCircleF';
import InfoOutlined from '@iam-com/icons/WarningCircle';
import CloseCircleFilled from '@iam-com/icons/CloseCircleF';
import WarningCircleF from '@iam-com/icons/WarningCircleF';
import { Button } from '../Button/index.js';
import { Tooltip } from '../Tooltip/index.js';
import clsx from 'clsx';
import { u as useFormatMessage } from '../_verture/useFormatMessage-703f8b20.js';
import { $ as $prefixCls } from '../_verture/constant-66aa48a1.js';
import { u as usePopupContainer } from '../_verture/usePopupContainer-87febeb9.js';
import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
import '../_verture/unsupportedIterableToArray-cb478f24.js';
import '../_verture/typeof-498dd2b1.js';
import '@iam-com/icons/LoadingF';
import '@iam-com/icons/Forbid';
import '@iam-com/icons/Down';
import '../_verture/index-fac03ce3.js';
import 'rc-dropdown';
import 'dayjs';
import '@iam-com/lib';
import 'rc-tooltip';
import 'rc-tooltip/lib/placements';
import '@para-ui/core/GlobalContext';

var en = {
  cancel: 'Cancel',
  ok: 'Ok'
};

var zh = {
  cancel: '取消',
  ok: '确定'
};

var localeJson = {
  zh: zh,
  en: en
};

var css_248z = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/2 下午1:44\n* @description\n*/\n/**\n* @author Hanz\n* @date 2021/10/20 下午2:08\n* @description color\n*/\n.paraui-v3-popconfirm.paraui-v3-tooltip {\n  position: absolute;\n  max-width: 600px;\n  padding: 0;\n  font-size: 14px;\n  color: initial;\n  background-color: rgb(255, 255, 255);\n  box-shadow: 0px 2px 8px 0px rgba(171, 176, 185, 0.4);\n  border-radius: 4px;\n}\n.paraui-v3-popconfirm.paraui-v3-tooltip .component-tooltip-inner {\n  min-width: auto;\n  min-height: auto;\n  padding: 0;\n  color: initial;\n  background-color: transparent;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper {\n  min-width: 350px;\n  padding: 24px;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-message {\n  position: relative;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-message-icon {\n  position: absolute;\n  top: 2px;\n  color: rgb(255, 161, 80);\n  line-height: 0;\n  font-size: 16px;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-message-icon svg {\n  color: inherit;\n  font-size: inherit;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-message-body {\n  padding-left: 24px;\n  line-height: 20px;\n  font-size: 14px;\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-message-title {\n  font-weight: 700;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-message-content {\n  font-weight: 400;\n  margin-top: 13px;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-btns {\n  margin-top: 32px;\n  text-align: right;\n}\n.paraui-v3-popconfirm .popconfirm-wrapper .popconfirm-btns > button + button {\n  margin-left: 16px;\n}";
styleInject(css_248z);

//图标
var iconMapping = {
  "success": jsx(CompleteIcon, {}),
  "warning": jsx(WarningCircleF, {}),
  "error": jsx(CloseCircleFilled, {}),
  "info": jsx(InfoOutlined, {})
};
//popConfirm
var PopConfirm = function PopConfirm(props) {
  var _props$trigger = props.trigger,
    trigger = _props$trigger === void 0 ? 'click' : _props$trigger,
    _props$type = props.type,
    type = _props$type === void 0 ? 'warning' : _props$type,
    title = props.title,
    content = props.content,
    icon = props.icon,
    okText = props.okText,
    cancelText = props.cancelText,
    onOk = props.onOk,
    onCancel = props.onCancel,
    okButtonProps = props.okButtonProps,
    cancelButtonProps = props.cancelButtonProps,
    _props$placement = props.placement,
    placement = _props$placement === void 0 ? 'bottom' : _props$placement,
    className = props.className,
    overlayClassName = props.overlayClassName,
    style = props.style,
    children = props.children,
    _props$open = props.open,
    open = _props$open === void 0 ? false : _props$open,
    _props$controllable = props.controllable,
    controllable = _props$controllable === void 0 ? false : _props$controllable,
    _props$showCancel = props.showCancel,
    showCancel = _props$showCancel === void 0 ? true : _props$showCancel,
    _props$bubble = props.bubble,
    bubble = _props$bubble === void 0 ? true : _props$bubble,
    actions = props.actions,
    onClose = props.onClose,
    customizeContainer = props.getPopupContainer,
    restProps = __rest(props, ["trigger", "type", "title", "content", "icon", "okText", "cancelText", "onOk", "onCancel", "okButtonProps", "cancelButtonProps", "placement", "className", "overlayClassName", "style", "children", "open", "controllable", "showCancel", "bubble", "actions", "onClose", "getPopupContainer"]);
  var intl = useFormatMessage('PopConfirm', localeJson);
  var wrapRef = React__default.useRef();
  var getPopupContainer = usePopupContainer(wrapRef, customizeContainer);
  //打开
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    inOpen = _useState2[0],
    setInOpen = _useState2[1];
  //取消
  var handleCancel = function handleCancel() {
    onCancel === null || onCancel === void 0 ? void 0 : onCancel();
    handleClose();
  };
  //确认
  var handleOk = function handleOk() {
    onOk === null || onOk === void 0 ? void 0 : onOk();
    handleClose();
  };
  //关闭
  var handleClose = function handleClose() {
    if (!controllable) {
      setInOpen(false);
      onClose === null || onClose === void 0 ? void 0 : onClose();
    }
  };
  //tooltip vis
  var onVisibleChange = function onVisibleChange(vis) {
    if (!controllable) {
      setInOpen(vis);
      if (!vis) onClose === null || onClose === void 0 ? void 0 : onClose();
    } else {
      if (open) onClose === null || onClose === void 0 ? void 0 : onClose();
    }
  };
  useEffect(function () {
    if (controllable) setInOpen(open);
  }, [open]);
  //渲染内容
  var renderOverlay = function renderOverlay() {
    var btns = jsxs(Fragment, {
      children: [showCancel && jsx(Button, Object.assign({
        onClick: handleCancel,
        variant: 'outlined',
        size: 'small'
      }, cancelButtonProps, {
        children: cancelText !== null && cancelText !== void 0 ? cancelText : intl({
          id: 'cancel'
        })
      })), jsx(Button, Object.assign({
        onClick: handleOk,
        variant: 'contained',
        size: 'small'
      }, okButtonProps, {
        children: okText !== null && okText !== void 0 ? okText : intl({
          id: 'ok'
        })
      }))]
    });
    return jsxs("div", Object.assign({
      className: clsx('popconfirm-wrapper'),
      style: style,
      onClick: function onClick(evt) {
        if (!bubble) evt.stopPropagation();
      }
    }, {
      children: [jsxs("div", Object.assign({
        className: 'popconfirm-message'
      }, {
        children: [jsx("span", Object.assign({
          className: 'popconfirm-message-icon'
        }, {
          children: icon || iconMapping[type]
        })), jsxs("div", Object.assign({
          className: 'popconfirm-message-body'
        }, {
          children: [title && jsx("div", Object.assign({
            className: 'popconfirm-message-title'
          }, {
            children: title
          })), jsx("div", Object.assign({
            className: 'popconfirm-message-content'
          }, {
            children: content
          }))]
        }))]
      })), jsx("div", Object.assign({
        className: 'popconfirm-btns'
      }, {
        children: actions !== null && actions !== void 0 ? actions : btns
      }))]
    }));
  };
  return jsx(Tooltip, Object.assign({}, restProps, {
    ref: wrapRef,
    trigger: trigger,
    open: inOpen,
    arrow: false,
    placement: placement,
    title: renderOverlay(),
    onVisibleChange: onVisibleChange,
    overlayClassName: clsx("".concat($prefixCls, "-popconfirm"), overlayClassName, className),
    getPopupContainer: getPopupContainer
  }, {
    children: children
  }));
};

export { PopConfirm, PopConfirm as default };
