import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import AppLayout from '@/layouts/app-layout';
import { type BreadcrumbItem } from '@/types';
import { Head, Link, router } from '@inertiajs/react';
import { ArrowLeft, Edit, Trash2, GraduationCap } from 'lucide-react';
import { showConfirmation, showSuccess, showError } from '@/lib/toast';

interface EducationLevel {
    id: number;
    name: string;
    description?: string;
    created_at: string;
    updated_at: string;
}

interface Props {
    educationLevel: EducationLevel;
}

export default function ShowEducationLevel({ educationLevel }: Props) {
    const breadcrumbs: BreadcrumbItem[] = [
        { title: 'Dashboard', href: '/dashboard' },
        { title: 'Niveles Educativos', href: '/education-levels' },
        { title: educationLevel.name, href: `/education-levels/${educationLevel.id}` },
    ];

    const handleDelete = () => {
        showConfirmation(
            `¿Estás seguro de que quieres eliminar el nivel educativo "${educationLevel.name}"?`,
            () => {
                router.delete(`/education-levels/${educationLevel.id}`, {
                    onSuccess: () => {
                        showSuccess('Nivel educativo eliminado exitosamente');
                    },
                    onError: () => {
                        showError('Error al eliminar el nivel educativo');
                    }
                });
            }
        );
    };

    return (
        <AppLayout breadcrumbs={breadcrumbs}>
            <Head title={educationLevel.name} />

            <div className="flex h-full flex-1 flex-col gap-4 p-4 lg:gap-6 lg:p-6">
                <div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
                    <div className="flex items-center gap-4">
                        <div className="p-2 bg-emerald-100 dark:bg-emerald-900/20 rounded-lg">
                            <GraduationCap className="w-8 h-8 text-emerald-600" />
                        </div>
                        <div>
                            <h1 className="text-3xl font-bold tracking-tight text-emerald-700 dark:text-emerald-400 sm:text-3xl">{educationLevel.name}</h1>
                            <p className="text-slate-600 dark:text-slate-400 mt-1 text-sm">
                                Detalles del nivel educativo
                            </p>
                        </div>
                    </div>
                    <div className="flex gap-2">
                        <Button variant="outline" asChild>
                            <Link href="/education-levels">
                                <ArrowLeft className="w-4 h-4 mr-2" />
                                Volver
                            </Link>
                        </Button>
                        <Button variant="outline" asChild>
                            <Link href={`/education-levels/${educationLevel.id}/edit`}>
                                <Edit className="w-4 h-4 mr-2" />
                                Editar
                            </Link>
                        </Button>
                        <Button
                            variant="destructive"
                            onClick={handleDelete}
                        >
                            <Trash2 className="w-4 h-4 mr-2" />
                            Eliminar
                        </Button>
                    </div>
                </div>

                <div className="grid gap-6">
                    <Card>
                        <CardHeader>
                            <CardTitle className="text-emerald-700 dark:text-emerald-400">Información General</CardTitle>
                            <CardDescription>
                                Datos básicos del nivel educativo
                            </CardDescription>
                        </CardHeader>
                        <CardContent className="space-y-4">
                            <div>
                                <label className="text-sm font-medium text-muted-foreground">Nombre</label>
                                <p className="text-lg font-semibold">{educationLevel.name}</p>
                            </div>

                            {educationLevel.description && (
                                <div>
                                    <label className="text-sm font-medium text-muted-foreground">Descripción</label>
                                    <p className="text-sm leading-relaxed mt-1">{educationLevel.description}</p>
                                </div>
                            )}
                        </CardContent>
                    </Card>

                    <Card>
                        <CardHeader>
                            <CardTitle>Información del Sistema</CardTitle>
                            <CardDescription>
                                Metadatos y fechas de registro
                            </CardDescription>
                        </CardHeader>
                        <CardContent className="space-y-4">
                            <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
                                <div>
                                    <label className="text-sm font-medium text-muted-foreground">ID</label>
                                    <p className="font-mono text-sm">{educationLevel.id}</p>
                                </div>
                                <div>
                                    <label className="text-sm font-medium text-muted-foreground">Fecha de Creación</label>
                                    <p className="text-sm">{new Date(educationLevel.created_at).toLocaleString('es-ES')}</p>
                                </div>
                                <div>
                                    <label className="text-sm font-medium text-muted-foreground">Última Actualización</label>
                                    <p className="text-sm">{new Date(educationLevel.updated_at).toLocaleString('es-ES')}</p>
                                </div>
                            </div>
                        </CardContent>
                    </Card>
                </div>
            </div>
        </AppLayout>
    );
}
