<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class IsUserVerifyEmail
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        // if(!Auth::guard('web')->user()->email_verified){
        //         Auth::guard('web')->logout();
        //         return redirect()->route('user.login')->with('error','You need to confirm your account. We have sent you an activation link, please check your email')->withInput();
        //     }
        //        if(!Auth::guard('web')->user()->status==0){
        //         return redirect()->route('user.login')->with('error','your account. De activation')->withInput();
    
        //        }
    
        if(Auth::guard('web')->check()&& auth()->user()->status == 1){
            Auth::guard('web')->logout();

            return redirect()->route('user.login')->with('error','Your account has been Banned. Please Contact Administrator');


        } elseif(Auth::guard('web')->check()&& auth()->user()->email_verified == 0){

            Auth::guard('web')->logout();
          
            return redirect()->route('user.login')->with('error','You need to confirm your account. We have sent you an activation link, please check your email');


        }
        return $next($request);
    }
}
