<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

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

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

        return $next($request);
    }
}
