<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class SuperAdminMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        if (!Auth::check()) {
            return redirect()->route('login');
        }

        $user = Auth::user();

        // Only allow super admins
        if ($user->isSuperAdmin()) {
            return $next($request);
        }

        return redirect()->route('home')->with('error', 'Only Super Admins can access this area.');
    }
}
