<?php
/**
 * Flash alert messages component — with Lucide icons and animations.
 */
$session = \App\Core\App::getInstance()->session();
$alerts = $session->getAlerts();

if (empty($alerts)) {
    return;
}

$iconSvg = [
    'success' => '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>',
    'error'   => '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>',
    'warning' => '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
    'info'    => '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',
];

$closeSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
?>
<?php foreach ($alerts as $alert): ?>
    <?php
    $type = $alert['type'] ?? 'info';
    $message = $alert['message'] ?? '';
    ?>
    <div class="alert alert-<?= $type ?>" data-auto-dismiss="5000">
        <div class="alert-content">
            <span class="alert-icon"><?= $iconSvg[$type] ?? $iconSvg['info'] ?></span>
            <span><?= e($message) ?></span>
        </div>
        <button class="alert-close" onclick="var el=this.parentElement;el.classList.add('dismissing');el.addEventListener('animationend',function(){el.remove();})"><?= $closeSvg ?></button>
    </div>
<?php endforeach; ?>
