<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class RequireSuperUser
{
    public function handle(Request $request, Closure $next)
    {
        $u = $request->user();
        $role = $u->role ?? 'user';

        // يسمح لـ admin و super فقط
        if (!$u || !in_array($role, ['admin', 'super'], true)) {
            return redirect()
                ->route('dashboard.sales')
                ->with('error', 'ليس لديك صلاحيات');
        }

        return $next($request);
    }
}
