<script setup>
import Checkbox from '@/Components/Checkbox.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import TextInput from '@/Components/TextInput.vue';
import { Head, Link, useForm } from '@inertiajs/vue3';

defineProps({
    canResetPassword: {
        type: Boolean,
    },
    status: {
        type: String,
    },
});

const form = useForm({
    email: '',
    password: '',
    remember: false,
});

const submit = () => {
    form.post(route('login'), {
        onFinish: () => form.reset('password'),
    });
};
</script>

<template>
    <Head title="Log in" />

    <div class="min-h-screen flex flex-col lg:flex-row bg-white">
        <!-- Panel Izquierdo: Formulario -->
        <div class="w-full lg:w-1/2 flex flex-col justify-center px-8 sm:px-16 md:px-24 lg:px-32 xl:px-40 py-12 relative z-10">
            
            <div class="w-full max-w-sm mx-auto">
                <!-- Logo -->
                <div class="flex items-center gap-2 mb-12">
                    <div class="w-8 h-8 rounded-lg bg-blue-600 flex items-center justify-center">
                        <svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
                        </svg>
                    </div>
                    <span class="text-xl font-bold text-slate-800 tracking-tight">Innova</span>
                </div>

                <!-- Encabezado -->
                <h1 class="text-3xl font-bold text-slate-900 mb-2">Ingreso al Sistema</h1>
                <p class="text-sm text-slate-500 mb-8">¡Bienvenido de nuevo! Por favor, ingresa tus credenciales.</p>

                <div v-if="status" class="mb-4 text-sm font-medium text-green-600 bg-green-50 p-3 rounded-lg">
                    {{ status }}
                </div>

                <form @submit.prevent="submit" class="space-y-5">
                    <!-- Email -->
                    <div>
                        <InputLabel for="email" value="Correo Electrónico" class="text-slate-700 font-medium mb-1.5 sr-only" />
                        <div class="relative">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <svg class="h-5 w-5 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
                                </svg>
                            </div>
                            <TextInput
                                id="email"
                                type="email"
                                class="pl-10 block w-full border-slate-200 focus:border-blue-600 focus:ring-blue-600 rounded-lg shadow-sm transition-shadow h-11"
                                v-model="form.email"
                                required
                                autofocus
                                autocomplete="username"
                                placeholder="Correo Electrónico"
                            />
                        </div>
                        <InputError class="mt-2" :message="form.errors.email" />
                    </div>

                    <!-- Contraseña -->
                    <div>
                        <InputLabel for="password" value="Contraseña" class="text-slate-700 font-medium mb-1.5 sr-only" />
                        <div class="relative">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <svg class="h-5 w-5 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
                                </svg>
                            </div>
                            <TextInput
                                id="password"
                                type="password"
                                class="pl-10 block w-full border-slate-200 focus:border-blue-600 focus:ring-blue-600 rounded-lg shadow-sm transition-shadow h-11"
                                v-model="form.password"
                                required
                                autocomplete="current-password"
                                placeholder="Contraseña"
                            />
                        </div>
                        <InputError class="mt-2" :message="form.errors.password" />
                    </div>

                    <!-- Opciones Adicionales -->
                    <div class="flex items-center justify-between mt-4">
                        <label class="flex items-center cursor-pointer">
                            <Checkbox name="remember" v-model:checked="form.remember" class="text-blue-600 rounded border-slate-300 focus:ring-blue-600" />
                            <span class="ms-2 text-sm text-slate-600 font-medium tracking-tight">Recordarme</span>
                        </label>

                        <Link
                            v-if="canResetPassword"
                            :href="route('password.request')"
                            class="text-sm font-semibold text-blue-600 hover:text-blue-700 transition-colors"
                        >
                            ¿Olvidaste tu contraseña?
                        </Link>
                    </div>

                    <!-- Botón -->
                    <div class="pt-4">
                        <button
                            type="submit"
                            class="w-full flex justify-center py-3 px-4 border border-transparent rounded-lg shadow-sm text-sm font-bold text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-600 transition-all duration-200"
                            :class="{ 'opacity-75 cursor-not-allowed': form.processing }"
                            :disabled="form.processing"
                        >
                            <svg v-if="form.processing" class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                            </svg>
                            Ingresar
                        </button>
                    </div>
                </form>

                <p class="mt-8 text-center text-sm text-slate-500 font-medium">
                    Gestión Inteligente de Siniestros
                </p>
            </div>
        </div>

        <!-- Panel Derecho: Ilustración -->
        <div class="hidden lg:flex lg:w-1/2 bg-gradient-to-br from-blue-700 to-indigo-900 relative overflow-hidden items-center justify-center p-12">
            <!-- Efectos de fondo abstracto -->
            <div class="absolute inset-0 z-0 opacity-20">
                <svg class="absolute top-0 left-0 w-full h-full" xmlns="http://www.w3.org/2000/svg">
                    <defs>
                        <pattern id="grid" width="60" height="60" patternUnits="userSpaceOnUse">
                            <path d="M 40 0 L 0 0 0 40" fill="none" stroke="white" stroke-width="1"/>
                        </pattern>
                    </defs>
                    <rect width="100%" height="100%" fill="url(#grid)" />
                </svg>
                <div class="absolute top-1/4 left-1/4 w-96 h-96 bg-white rounded-full mix-blend-overlay filter blur-3xl opacity-50 animate-pulse"></div>
                <div class="absolute bottom-1/4 right-1/4 w-96 h-96 bg-cyan-400 rounded-full mix-blend-overlay filter blur-3xl opacity-30 animate-pulse" style="animation-delay: 2s;"></div>
            </div>

            <!-- Ilustración principal basada en la imagen -->
            <div class="relative z-10 w-full max-w-md">
                <div class="relative w-full aspect-square">
                    <!-- Círculos de fondo -->
                    <div class="absolute inset-0 rounded-full border border-white/20 scale-75"></div>
                    <div class="absolute inset-0 rounded-full border border-white/10 scale-90"></div>
                    <div class="absolute inset-0 rounded-full border border-white/5 scale-105"></div>

                    <!-- Líneas conectoras -->
                    <svg class="absolute inset-0 w-full h-full text-white/40" viewBox="0 0 100 100">
                        <!-- Left vertical line -->
                        <path d="M 30 35 L 30 65" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" />
                        <!-- Horizontal connections from nodes -->
                        <path d="M 30 35 L 55 35" fill="none" stroke="currentColor" stroke-width="2" />
                        <path d="M 30 50 L 55 50" fill="none" stroke="currentColor" stroke-width="2" />
                        <path d="M 30 65 L 55 65" fill="none" stroke="currentColor" stroke-width="2" />
                        <!-- Vertical line before card -->
                        <path d="M 55 35 L 55 65" fill="none" stroke="currentColor" stroke-width="2" />
                        <!-- Connection into card -->
                        <path d="M 55 50 L 65 50" fill="none" stroke="currentColor" stroke-width="2" />
                    </svg>

                    <!-- Iconos de seguros/siniestros flotantes izq -->
                    <div class="absolute top-[20%] left-[15%] w-16 h-16 bg-white/10 backdrop-blur-md rounded-2xl shadow-xl flex items-center justify-center transform hover:scale-110 transition-transform duration-300 border border-white/20">
                        <svg class="w-8 h-8 text-amber-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>
                    </div>

                    <div class="absolute top-[45%] left-[5%] w-24 h-24 bg-white rounded-3xl shadow-2xl flex flex-col items-center justify-center transform hover:scale-110 transition-transform duration-300 border-4 border-blue-100/30">
                        <div class="w-12 h-12 rounded-xl bg-blue-100 flex items-center justify-center text-blue-600 mb-1">
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path></svg>
                        </div>
                        <span class="text-[10px] font-bold text-slate-800 tracking-wider">TALLERES</span>
                    </div>

                    <div class="absolute bottom-[15%] left-[20%] w-16 h-16 bg-white/10 backdrop-blur-md rounded-2xl shadow-xl flex items-center justify-center transform hover:scale-110 transition-transform duration-300 border border-white/20">
                        <svg class="w-8 h-8 text-emerald-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
                    </div>

                    <!-- Tarjeta de Siniestro (Derecha) -->
                    <div class="absolute top-[30%] right-[0%] w-72 bg-white rounded-2xl shadow-2xl p-5 transform hover:-translate-y-2 transition-transform duration-300 border border-slate-100">
                        <div class="flex items-center justify-between mb-4 border-b border-slate-100 pb-3">
                            <div class="flex items-center gap-2">
                                <div class="w-8 h-8 rounded-full bg-rose-100 flex items-center justify-center">
                                    <svg class="w-4 h-4 text-rose-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
                                </div>
                                <div>
                                    <p class="text-xs font-bold text-slate-800">Siniestro #CAS-8920</p>
                                    <p class="text-[10px] text-slate-500">Alta severidad</p>
                                </div>
                            </div>
                            <span class="bg-blue-100 text-blue-700 text-[10px] font-bold px-2 py-1 rounded-full">EN TALLER</span>
                        </div>
                        <div class="space-y-4">
                            <!-- Progreso -->
                            <div>
                                <div class="flex justify-between text-xs mb-1">
                                    <span class="font-medium text-slate-600">Reparación</span>
                                    <span class="font-bold text-blue-600">75%</span>
                                </div>
                                <div class="w-full h-2 bg-slate-100 rounded-full overflow-hidden">
                                    <div class="h-full bg-blue-600 w-3/4 rounded-full"></div>
                                </div>
                            </div>
                            
                            <!-- Actividad Reciente -->
                            <div class="space-y-2 pt-2">
                                <div class="flex items-start gap-3">
                                    <div class="w-6 h-6 rounded-full bg-slate-100 flex items-center justify-center mt-0.5">
                                        <div class="w-2 h-2 rounded-full bg-slate-400"></div>
                                    </div>
                                    <div>
                                        <p class="text-xs font-semibold text-slate-700">Cotización aprobada</p>
                                        <p class="text-[10px] text-slate-400">Hace 2 horas por Ajustador</p>
                                    </div>
                                </div>
                                <div class="flex items-start gap-3">
                                    <div class="w-6 h-6 rounded-full bg-slate-100 flex items-center justify-center mt-0.5">
                                        <div class="w-2 h-2 rounded-full bg-slate-400"></div>
                                    </div>
                                    <div>
                                        <p class="text-xs font-semibold text-slate-700">Ingreso a Taller Norte</p>
                                        <p class="text-[10px] text-slate-400">Ayer a las 14:30</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Textos Inferiores -->
                <div class="text-center mt-8 space-y-3 relative z-10 max-w-lg mx-auto">
                    <h2 class="text-3xl font-bold text-white tracking-tight">Control total de siniestros.</h2>
                    <p class="text-blue-100 text-sm tracking-wide leading-relaxed">Coordina talleres, ajustadores y aseguradoras en una sola plataforma integrada y moderna.</p>
                    
                    <div class="flex justify-center gap-2 pt-6">
                        <div class="w-2 h-2 rounded-full bg-white"></div>
                        <div class="w-2 h-2 rounded-full bg-white/30"></div>
                        <div class="w-2 h-2 rounded-full bg-white/30"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style>
/* Animaciones súper sutiles */
@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}
.floating-element {
    animation: float 6s ease-in-out infinite;
}
</style>
