<?php
// /logout.php
// File logout universal untuk semua role (Super Admin & Branch)

require_once __DIR__ . '/includes/auth.php';

// 1. Hapus semua data session
$_SESSION = [];

// 2. Hapus cookie session (jika ada)
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(
        session_name(), 
        '', 
        time() - 42000,
        $params["path"], 
        $params["domain"],
        $params["secure"], 
        $params["httponly"]
    );
}

// 3. Destroy session
if (session_status() === PHP_SESSION_ACTIVE) {
    session_destroy();
}

// 4. Mulai session baru hanya untuk flash message
session_start();
$_SESSION['flash_message'] = 'Anda telah berhasil logout.';
$_SESSION['flash_type'] = 'success';

// 5. Redirect ke halaman login
header('Location: /login.php');
exit;