<?php
namespace App\Utils;

class Flasher {
    public static function setFlash($message, $type = 'success') {
        $_SESSION['flash'] = [
            'message' => $message,
            'type' => $type
        ];
    }

    public static function flash() {
        if (
            isset($_SESSION['flash']) &&
            is_array($_SESSION['flash']) &&
            isset($_SESSION['flash']['message'], $_SESSION['flash']['type'])
        ) {
            $flash = $_SESSION['flash'];
            echo "<div class='flash-message flash-{$flash['type']}'>{$flash['message']}</div>";
            unset($_SESSION['flash']);
        }
    }
}
