/**
 * Alert/Confirm Wrapper for Modern Message Box
 * This file overrides native alert/confirm with modern message boxes
 * Include this AFTER modern-messagebox.js
 */

// Store original functions
window._originalAlert = window.alert;
window._originalConfirm = window.confirm;
window._originalPrompt = window.prompt;

// Override alert
window.alert = function(message) {
    // For async compatibility, return immediately but show message
    setTimeout(() => {
        MsgBox.alert(String(message), 'info');
    }, 0);
};

// Override confirm - Returns promise for async, but tries to handle sync calls
window.confirm = function(message) {
    // For synchronous calls, we need to use a blocking approach
    // This is a limitation - modern browsers don't support true sync prompts
    console.warn('Synchronous confirm() called. Consider using MsgBox.confirm() with .then() instead.');
    
    // Fall back to native confirm for now, or use MsgBox in async context
    return window._originalConfirm(message);
};

// Override prompt
window.prompt = function(message, defaultValue) {
    console.warn('Synchronous prompt() called. Consider using MsgBox.prompt() with .then() instead.');
    return window._originalPrompt(message, defaultValue);
};

/**
 * Helper function to convert callback-style code to use modern message boxes
 */
window.modernAlert = async function(message, type = 'info') {
    return await MsgBox.alert(message, type);
};

window.modernConfirm = async function(message, options) {
    return await MsgBox.confirm(message, options);
};

window.modernPrompt = async function(message, defaultValue, placeholder) {
    return await MsgBox.prompt(message, defaultValue, placeholder);
};
