<div>
    <?php

use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Validate;
use Livewire\Volt\Component;

new #[Layout('components.layouts.auth')] class extends Component {
    #[Validate('required|string|email')]
    public string $email = '';

    #[Validate('required|string')]
    public string $password = '';

    public bool $remember = false;

    public function login(): void
    {
        $this->validate();

        $this->ensureIsNotRateLimited();

        if (!Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) {
            RateLimiter::hit($this->throttleKey());

            throw ValidationException::withMessages([
                'email' => __('auth.failed'),
            ]);
        }

        RateLimiter::clear($this->throttleKey());
        Session::regenerate();

        $this->redirectIntended(default: route('dashboard', absolute: false), navigate: false);
    }

    protected function ensureIsNotRateLimited(): void
    {
        if (!RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
            return;
        }

        event(new Lockout(request()));

        $seconds = RateLimiter::availableIn($this->throttleKey());

        throw ValidationException::withMessages([
            'email' => __('auth.throttle', [
                'seconds' => $seconds,
                'minutes' => ceil($seconds / 60),
            ]),
        ]);
    }

    protected function throttleKey(): string
    {
        return Str::transliterate(Str::lower($this->email) . '|' . request()->ip());
    }
};

    ?>

    <div class="p-4 shadow bg-warning rounded-0 mx-auto" style="max-width: 600px; width: 100%;">
        @if(session('account_deleted'))
            <div class="alert alert-success">
                {{ session('account_deleted') }}
            </div>
        @endif
        <h3 class="text-center mb-4">{{ __('Login') }}</h3>

        @if (session('status'))
            <div class="alert alert-success text-center mb-3">
                {{ session('status') }}
            </div>
        @endif

        <form wire:submit.prevent="login">
            <!-- Email -->
            <div class="form-group mb-3">
                <input type="email" wire:model.defer="email" class="form-control rounded-0"
                    placeholder="{{ __('Email') }}" required autofocus>
                @error('email') <small class="text-danger">{{ $message }}</small> @enderror
            </div>

            <!-- Password -->
            <div class="form-group mb-3">
                <input type="password" wire:model.defer="password" class="form-control rounded-0"
                    placeholder="{{ __('Password') }}" required>
                @error('password') <small class="text-danger">{{ $message }}</small> @enderror
            </div>

            <!-- Remember Me -->
            <div class="form-check mb-3">
                <input type="checkbox" wire:model="remember" class="form-check-input" id="remember">
                <label class="form-check-label" for="remember">{{ __('Remember me') }}</label>
            </div>

            <!-- Submit -->
            <div class="form-group mb-3">
                <button type="submit" class="btn btn-lg btn-primary bg-dark rounded-0 w-100">{{ __('Log in') }}</button>
            </div>

            <!-- Forgot Password -->
            @if (Route::has('password.request'))
                <div class="text-center">
                    <a class="text-danger text-lg" href="{{ route('password.request') }}">
                        <strong>{{ __('Forgot your password?  Click here') }}</strong></a>
                </div>
            @endif
        </form>

        <!-- Register Link -->
        @if (Route::has('register'))
            <div class="text-center text mt-3">
                <span><strong>{{ __("Don't have an account?") }}</strong></span>
                <a class="text-success" href="{{ route('register') }}"><strong>{{ __('Sign up') }}</strong></a>
            </div>
        @endif
    </div>

</div>