/**
 * Module-level confirm dialog utility
 * Replaces window.confirm() with a styled modal dialog
 * Usage: const ok = await confirmDialog('정말 삭제하시겠습니까?');
 */

type ConfirmResolver = (value: boolean) => void;
type ShowHandler = (message: string, resolver: ConfirmResolver) => void;

let _show: ShowHandler | null = null;

export function setConfirmHandler(handler: ShowHandler | null) {
    _show = handler;
}

export function confirmDialog(message: string): Promise<boolean> {
    if (!_show) return Promise.resolve(window.confirm(message));
    return new Promise(resolve => _show!(message, resolve));
}
