<?php

namespace App\Filament\Auth;

use Filament\Actions\Action;
use Filament\Auth\Pages\Login as BaseLogin;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Component;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;

class Login extends BaseLogin
{
    public function getHeading(): string | Htmlable
    {
        return new HtmlString(
            '<div class="flex flex-col items-center">
                <div class="w-16 h-16 rounded-full bg-gradient-to-br from-blue-800 to-blue-600 flex items-center justify-center shadow-lg shadow-blue-200/50 mb-3">
                    <svg class="w-8 h-8 text-white" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M8.25 21v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21m0 0h4.5V3.545M12.75 21h7.5V10.75M2.25 21h1.5m18 0h-18M2.25 9l4.5-1.636M18.75 3l-1.5.545m0 6.205 3 1m1.5.5-1.5-.5M6.75 7.364V3h-3v18m3-13.636 10.5-3.819" />
                    </svg>
                </div>
                <span class="text-2xl font-extrabold text-blue-900">Admin Desa Cemara</span>
            </div>'
        );
    }

    public function getSubheading(): string | Htmlable | null
    {
        return new HtmlString(
            '<span class="text-gray-500 text-sm">Masuk untuk mengelola <strong class="text-blue-700">Sistem Informasi Desa</strong></span>'
        );
    }

    protected function getEmailFormComponent(): Component
    {
        return TextInput::make('email')
            ->label('Email')
            ->email()
            ->required()
            ->autocomplete()
            ->autofocus()
            ->placeholder('admin@desacemara.desa.id')
            ->extraInputAttributes(['tabindex' => 1])
            ->prefixIcon('heroicon-m-envelope');
    }

    protected function getPasswordFormComponent(): Component
    {
        return TextInput::make('password')
            ->label('Password')
            ->hint(new HtmlString('<a href="' . url('/admin/lupa-password') . '" tabindex="3" class="text-sm text-blue-600 hover:text-blue-500 transition-colors">Lupa password?</a>'))
            ->password()
            ->revealable(filament()->arePasswordsRevealable())
            ->autocomplete('current-password')
            ->required()
            ->placeholder('Masukkan password')
            ->extraInputAttributes(['tabindex' => 2])
            ->prefixIcon('heroicon-m-lock-closed');
    }

    protected function getRememberFormComponent(): Component
    {
        return Checkbox::make('remember')
            ->label('Ingat saya');
    }

    protected function getAuthenticateFormAction(): Action
    {
        return parent::getAuthenticateFormAction()
            ->label('Masuk')
            ->icon('heroicon-m-arrow-right-end-on-rectangle');
    }

    public function getTitle(): string | Htmlable
    {
        return 'Login Admin Desa';
    }
}
