<?php

namespace App\Http\Middleware;

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

class CheckUserStatus
{
    public function handle($request, Closure $next)
    {
        $user = Auth::user();

        if ($user && ($user->status === 'locked' || $user->status === 'banned')) {
            Auth::logout(); // Logout user
            return redirect('/')->with('status', 'Akun Anda telah di kunci. Silahkan hubungi Customer Service untuk detail lebih lanjut.');
        }

        return $next($request);
    }
}