// ============================================================
// Mago4 Demo — helper frontend
// ============================================================
// Genera una field-row in stile form Mago4
function field(label, value) {
return `
`;
}
// Modal generico
function openGenericModal(title, html) {
const t = document.getElementById('gmTitle');
const b = document.getElementById('gmBody');
if (t) t.textContent = title;
if (b) b.innerHTML = html;
const m = document.getElementById('genericModal');
if (m) m.classList.add('show');
}
function closeGenericModal() {
const m = document.getElementById('genericModal');
if (m) m.classList.remove('show');
}
// Ricerca globale (demo)
function globalSearch(q) {
if (!q || !q.trim()) return;
alert('Ricerca globale (demo): "' + q + '"');
}
// Formattazione valuta
function fmtEur(v) {
return new Intl.NumberFormat('it-IT', { style: 'currency', currency: 'EUR' }).format(v || 0);
}
function fmtDate(s) {
if (!s) return '—';
return new Date(s).toLocaleDateString('it-IT');
}
// Toast notifiche
function showNotification(message, type) {
const n = document.createElement('div');
n.textContent = message;
n.style.cssText = `position:fixed;top:64px;right:20px;padding:11px 18px;border-radius:4px;
background:${type === 'error' ? '#D32F2F' : '#1577be'};color:#fff;
box-shadow:0 4px 16px rgba(0,0,0,0.2);z-index:2000;font-size:13px;animation:slideIn .25s ease;`;
document.body.appendChild(n);
setTimeout(() => n.remove(), 3000);
}
document.addEventListener('keydown', e => {
if (e.key === 'Escape') document.querySelectorAll('.modal.show').forEach(m => m.classList.remove('show'));
});
const _style = document.createElement('style');
_style.textContent = `@keyframes slideIn{from{transform:translateX(60px);opacity:0}to{transform:none;opacity:1}}`;
document.head.appendChild(_style);