<?php
/**
 * Flash message partial — handles the keyed format: $_SESSION['flash'][$type] = $message
 */
if (!empty($_SESSION['flash'])):
    foreach ($_SESSION['flash'] as $type => $message):
        // Normalize type
        if ($type === 'danger') $type = 'error';
        $icon = match($type) {
            'success' => 'check-circle',
            'error'   => 'exclamation-circle',
            'warning' => 'exclamation-triangle',
            default   => 'info-circle',
        };
?>
    <div class="alert alert-<?= $type ?>" role="alert" style="display:flex;align-items:center;gap:10px;">
        <i class="fas fa-<?= $icon ?> alert-icon"></i>
        <div class="alert-content" style="flex:1;"><?= htmlspecialchars((string)$message) ?></div>
        <button class="alert-dismiss" onclick="this.closest('.alert').remove()" aria-label="Dismiss">
            <i class="fas fa-times"></i>
        </button>
    </div>
<?php
    endforeach;
    unset($_SESSION['flash']);
endif;
?>
