/** * Global Alert Helper for Mivo * Provides a standardized way to trigger premium SweetAlert2 dialogs. */ const Mivo = { /** * Show a simple alert dialog. * @param {string} type - 'success', 'error', 'warning', 'info', 'question' * @param {string} title - The title of the alert * @param {string} message - The body text/HTML * @returns {Promise} */ alert: function(type, title, message = '') { const typeMap = { 'success': { icon: 'check-circle-2', color: 'text-success' }, 'error': { icon: 'x-circle', color: 'text-error' }, 'warning': { icon: 'alert-triangle', color: 'text-warning' }, 'info': { icon: 'info', color: 'text-info' }, 'question':{ icon: 'help-circle', color: 'text-question' } }; const config = typeMap[type] || typeMap['info']; return Swal.fire({ iconHtml: ``, title: title, html: message, confirmButtonText: 'OK', customClass: { popup: 'swal2-premium-card', confirmButton: 'btn btn-primary', cancelButton: 'btn btn-secondary', }, buttonsStyling: false, heightAuto: false, didOpen: () => { if (typeof lucide !== 'undefined') lucide.createIcons(); } }); }, /** * Show a confirmation dialog. * @param {string} title - The title of the confirmation * @param {string} message - The body text/HTML * @param {string} confirmText - Text for the confirm button * @param {string} cancelText - Text for the cancel button * @returns {Promise} Resolves if confirmed, rejects if cancelled */ confirm: function(title, message = '', confirmText = 'Yes, Proceed', cancelText = 'Cancel') { return Swal.fire({ iconHtml: ``, title: title, html: message, showCancelButton: true, confirmButtonText: confirmText, cancelButtonText: cancelText, customClass: { popup: 'swal2-premium-card', confirmButton: 'btn btn-primary', cancelButton: 'btn btn-secondary', }, buttonsStyling: false, reverseButtons: true, heightAuto: false, didOpen: () => { if (typeof lucide !== 'undefined') lucide.createIcons(); } }).then(result => result.isConfirmed); }, /** * Show a premium stacking toast. * @param {string} type - 'success', 'error', 'warning', 'info' * @param {string} title - Title * @param {string} message - Body text * @param {number} duration - ms before auto-close */ toast: function(type, title, message = '', duration = 5000) { let container = document.getElementById('mivo-toast-container'); if (!container) { container = document.createElement('div'); container.id = 'mivo-toast-container'; document.body.appendChild(container); } const typeMap = { 'success': { icon: 'check-circle-2', color: 'text-success' }, 'error': { icon: 'x-circle', color: 'text-error' }, 'warning': { icon: 'alert-triangle', color: 'text-warning' }, 'info': { icon: 'info', color: 'text-info' } }; const config = typeMap[type] || typeMap['info']; const toast = document.createElement('div'); toast.className = `mivo-toast ${config.color}`; toast.innerHTML = `