<?php

use App\Livewire\Forms\LoginForm;
use Illuminate\Support\Facades\Session;
use Livewire\Attributes\Layout;
use Livewire\Volt\Component;

new #[Layout('layouts.guest')] class extends Component
{
    public LoginForm $form;

    /**
     * Handle an incoming authentication request.
     */
    public function login(): void
    {
        $this->validate();

        $this->form->authenticate();

        Session::regenerate();

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

<div>
    <h2 class="text-xl font-semibold text-t1 mb-1">Sign in</h2>
    <p class="text-sm text-t2 mb-6">Welcome back to Nimuli</p>

    <!-- Session Status -->
    <x-auth-session-status class="mb-4" :status="session('status')" />

    <form wire:submit="login">
        <!-- Email Address -->
        <div>
            <x-input-label for="email" :value="__('Email')" />
            <x-text-input wire:model="form.email" id="email" type="email" name="email" required autofocus autocomplete="username" />
            <x-input-error :messages="$errors->get('form.email')" />
        </div>

        <!-- Password -->
        <div class="mt-4">
            <x-input-label for="password" :value="__('Password')" />
            <x-text-input wire:model="form.password" id="password" type="password" name="password" required autocomplete="current-password" />
            <x-input-error :messages="$errors->get('form.password')" />
        </div>

        <!-- Remember Me + Forgot Password -->
        <div class="flex items-center justify-between mt-4">
            <label class="flex items-center gap-2 text-sm text-t2 cursor-pointer">
                <input wire:model="form.remember" type="checkbox" class="rounded bg-s2 border-white/[.06] text-blue">
                Remember me
            </label>

            @if (Route::has('password.request'))
                <a class="text-sm text-blue hover:underline" href="{{ route('password.request') }}" wire:navigate>
                    Forgot password?
                </a>
            @endif
        </div>

        <x-primary-button class="mt-6">
            Sign in
        </x-primary-button>
    </form>

    <p class="mt-6 text-center text-sm text-t2">
        Don't have an account?
        <a href="{{ route('register') }}" class="text-blue hover:underline" wire:navigate>Create one</a>
    </p>
</div>
