<?php
// Reads flash messages if your project stores them in $_SESSION['flash'].
// Expected format examples:
// $_SESSION['flash'][] = ['type'=>'success','message'=>'Saved'];
// $_SESSION['flash'][] = ['type'=>'danger','message'=>'Error'];
if (session_status() !== PHP_SESSION_ACTIVE) { @session_start(); }
$flashes = $_SESSION['flash'] ?? [];
if (!is_array($flashes)) $flashes = [];
// Keep them only once
$_SESSION['flash'] = [];
?>
<div class="toast-container position-fixed top-0 end-0 p-3" style="z-index:9999">
  <?php foreach ($flashes as $f): ?>
    <?php
      $type = (string)($f['type'] ?? 'info');
      $msg  = (string)($f['message'] ?? '');
      $bg = 'text-bg-primary';
      if ($type === 'success') $bg = 'text-bg-success';
      if ($type === 'danger' || $type === 'error') $bg = 'text-bg-danger';
      if ($type === 'warning') $bg = 'text-bg-warning';
      if ($type === 'info') $bg = 'text-bg-info';
    ?>
    <div class="toast <?= e($bg) ?> border-0 rounded-4 shadow-sm mb-2" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="4500">
      <div class="d-flex">
        <div class="toast-body fw-semibold"><?= e($msg) ?></div>
        <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
      </div>
    </div>
  <?php endforeach; ?>
</div>
