"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useConfirmDialog = useConfirmDialog;
const react_1 = __importDefault(require("react"));
/**
 * A custom hook that manages the state and behavior of a confirmation dialog.
 *
 * @template TData - The type of the data associated with the dialog.
 *
 * @param {UseConfirmDialog} param0 - An object containing the onConfirm callback.
 * @param {Function} [param0.onConfirm] - A callback function that is called when the dialog is confirmed.
 *
 * @returns {Object} An object containing the dialog state and handlers.
 * @returns {string} id - The current id associated with the dialog.
 * @returns {TData | null} data - The current data associated with the dialog.
 * @returns {Function} handleDialogOpen - A function to open the dialog with a specific id and optional data.
 * @returns {Object} dialogProps - An object containing the dialog properties and handlers.
 */
function useConfirmDialog({ onConfirm: onConfirmProp }) {
    const [id, setId] = react_1.default.useState('');
    const [data, setData] = react_1.default.useState(null);
    const [open, setOpen] = react_1.default.useState(false);
    const onOpenChange = (open) => setOpen(open);
    const handleDialogOpen = (id, data) => {
        setId(id);
        setData(data);
        setOpen(true);
    };
    const handleDialogClose = () => setOpen(false);
    const onCancel = () => {
        setId('');
        setData(null);
        setOpen(false);
    };
    const onConfirm = () => {
        setId('');
        setData(null);
        onConfirmProp?.(id);
    };
    return {
        id,
        data,
        handleDialogClose,
        handleDialogOpen,
        dialogProps: {
            open,
            onOpenChange,
            onCancel,
            onConfirm
        }
    };
}
