import { __assign, __rest } from "tslib";
import React, { useContext, useState } from 'react';
import classNames from 'classnames';
import Popover from '../popover';
import Button from '../button';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { WarningCircle } from '../_utils/components';
var PopConfirm = function (props) {
    var _a = props.placement, placement = _a === void 0 ? 'top' : _a, _b = props.confirmText, confirmText = _b === void 0 ? 'Yes' : _b, _c = props.cancelText, cancelText = _c === void 0 ? 'No' : _c, title = props.title, icon = props.icon, onConfirm = props.onConfirm, onCancel = props.onCancel, onVisibleChange = props.onVisibleChange, className = props.className, children = props.children, customisedCls = props.prefixCls, otherProps = __rest(props, ["placement", "confirmText", "cancelText", "title", "icon", "onConfirm", "onCancel", "onVisibleChange", "className", "children", "prefixCls"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('pop-confirm', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className);
    var _d = useState(false), visible = _d[0], setVisible = _d[1];
    var cancelOnClick = function (e) {
        setVisible(false);
        onCancel && onCancel(e);
    };
    var confirmOnClick = function (e) {
        setVisible(false);
        onConfirm && onConfirm(e);
    };
    var overlay = function () {
        return (React.createElement("div", { className: prefixCls + "__overlay" },
            React.createElement("div", { className: prefixCls + "__messages" },
                icon ? icon : React.createElement(WarningCircle, { size: 14 }),
                React.createElement("span", { className: prefixCls + "__title" }, title)),
            React.createElement("div", { className: prefixCls + "__buttons" },
                React.createElement(Button, { size: "sm", onClick: cancelOnClick }, cancelText),
                React.createElement(Button, { size: "sm", btnType: "primary", onClick: confirmOnClick }, confirmText))));
    };
    return (React.createElement(Popover, __assign({}, otherProps, { className: cls, role: "alertdialog", visible: visible, onVisibleChange: function (val) {
            setVisible(val);
            onVisibleChange && onVisibleChange(val);
        }, content: overlay(), placement: placement }), children));
};
PopConfirm.displayName = 'PopConfirm';
export default PopConfirm;
//# sourceMappingURL=index.js.map