"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vue_1 = require("vue");
const popover_1 = require("../../popover");
const Popover_1 = require("../../popover/src/Popover");
const _utils_1 = require("../../_utils");
const _mixins_1 = require("../../_mixins");
const styles_1 = require("../styles");
const PopconfirmPanel_1 = require("./PopconfirmPanel");
const index_cssr_1 = require("./styles/index.cssr");
const interface_1 = require("./interface");
const popconfirmProps = Object.assign(Object.assign(Object.assign({}, _mixins_1.useTheme.props), Popover_1.popoverBaseProps), { positiveText: String, negativeText: String, showIcon: {
        type: Boolean,
        default: true
    }, trigger: {
        type: String,
        default: 'click'
    }, onPositiveClick: Function, onNegativeClick: Function });
exports.default = (0, vue_1.defineComponent)({
    name: 'Popconfirm',
    props: popconfirmProps,
    __popover__: true,
    setup(props) {
        const { mergedClsPrefixRef } = (0, _mixins_1.useConfig)();
        const themeRef = (0, _mixins_1.useTheme)('Popconfirm', 'Popconfirm', index_cssr_1.default, styles_1.popconfirmLight, props, mergedClsPrefixRef);
        const popoverInstRef = (0, vue_1.ref)(null);
        function handlePositiveClick(e) {
            const { onPositiveClick, 'onUpdate:show': onUpdateShow } = props;
            void Promise.resolve(onPositiveClick ? onPositiveClick(e) : true).then((value) => {
                var _a;
                if (value === false)
                    return;
                (_a = popoverInstRef.value) === null || _a === void 0 ? void 0 : _a.setShow(false);
                if (onUpdateShow)
                    (0, _utils_1.call)(onUpdateShow, false);
            });
        }
        function handleNegativeClick(e) {
            const { onNegativeClick, 'onUpdate:show': onUpdateShow } = props;
            void Promise.resolve(onNegativeClick ? onNegativeClick(e) : true).then((value) => {
                var _a;
                if (value === false)
                    return;
                (_a = popoverInstRef.value) === null || _a === void 0 ? void 0 : _a.setShow(false);
                if (onUpdateShow)
                    (0, _utils_1.call)(onUpdateShow, false);
            });
        }
        (0, vue_1.provide)(interface_1.popconfirmInjectionKey, {
            mergedThemeRef: themeRef,
            mergedClsPrefixRef
        });
        return {
            mergedTheme: themeRef,
            popoverInstRef,
            handlePositiveClick,
            handleNegativeClick
        };
    },
    render() {
        const { $slots: slots, $props: props, mergedTheme } = this;
        return (0, vue_1.h)(popover_1.NPopover, (0, _utils_1.omit)(props, PopconfirmPanel_1.panelPropKeys, {
            theme: mergedTheme.peers.Popover,
            themeOverrides: mergedTheme.peerOverrides.Popover,
            internalExtraClass: ['popconfirm'],
            ref: 'popoverInstRef'
        }), {
            trigger: slots.activator || slots.trigger,
            default: () => {
                const panelProps = (0, _utils_1.keep)(props, PopconfirmPanel_1.panelPropKeys);
                return (0, vue_1.h)(PopconfirmPanel_1.default, Object.assign(Object.assign({}, panelProps), { onPositiveClick: this.handlePositiveClick, onNegativeClick: this.handleNegativeClick }), slots);
            }
        });
    }
});
