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, Lightbulb } from 'lucide-react';
import { showConfirmation, showSuccess, showError } from '@/lib/toast';

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

interface Props {
    enfoquePedagogico: EnfoquePedagogico;
}

export default function EnfoquePedagogicosShow({ enfoquePedagogico }: Props) {
    const breadcrumbs: BreadcrumbItem[] = [
        { title: 'Dashboard', href: '/dashboard' },
        { title: 'Enfoques Pedagógicos', href: '/enfoque-pedagogicos' },
        { title: enfoquePedagogico.name, href: `/enfoque-pedagogicos/${enfoquePedagogico.id}` },
    ];

    const handleDelete = () => {
        showConfirmation(
            `¿Estás seguro de que quieres eliminar el enfoque pedagógico "${enfoquePedagogico.name}"?`,
            () => {
                router.delete(`/enfoque-pedagogicos/${enfoquePedagogico.id}`, {
                    onSuccess: () => {
                        showSuccess('Enfoque pedagógico eliminado exitosamente');
                    },
                    onError: () => {
                        showError('Error al eliminar el enfoque pedagógico');
                    }
                });
            }
        );
    };

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

            <div className="flex h-full flex-1 flex-col gap-6 rounded-xl p-6">
                <div className="flex items-center justify-between">
                    <div className="flex items-center gap-4">
                        <div className="flex items-center gap-3">
                            <div className="p-2 bg-emerald-100 dark:bg-emerald-900/20 rounded-lg">
                                <Lightbulb className="w-6 h-6 text-emerald-600 dark:text-emerald-400" />
                            </div>
                            <div>
                                <h1 className="text-3xl font-bold text-emerald-700 dark:text-emerald-400">
                                    {enfoquePedagogico.name}
                                </h1>
                                <p className="text-slate-600 dark:text-slate-400 mt-1">
                                    Detalles del enfoque pedagógico
                                </p>
                            </div>
                        </div>
                    </div>
                    <div className="flex gap-2">
                        <Button variant="outline" asChild>
                            <Link href="/enfoque-pedagogicos">
                                <ArrowLeft className="w-4 h-4 mr-2" />
                                Volver
                            </Link>
                        </Button>
                        <Button variant="outline" asChild>
                            <Link href={`/enfoque-pedagogicos/${enfoquePedagogico.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="max-w-2xl">
                    <Card>
                        <CardHeader>
                            <CardTitle className="text-emerald-700 dark:text-emerald-400">
                                Información del Enfoque Pedagógico
                            </CardTitle>
                            <CardDescription>
                                Detalles completos del enfoque pedagógico
                            </CardDescription>
                        </CardHeader>
                        <CardContent className="space-y-6">
                            <div className="grid grid-cols-1 gap-6">
                                <div>
                                    <label className="text-sm font-medium text-slate-900 dark:text-white">
                                        Nombre
                                    </label>
                                    <p className="mt-1 text-slate-700 dark:text-slate-300 bg-slate-50 dark:bg-slate-800/50 p-3 rounded-lg">
                                        {enfoquePedagogico.name}
                                    </p>
                                </div>

                                {enfoquePedagogico.description && (
                                    <div>
                                        <label className="text-sm font-medium text-slate-900 dark:text-white">
                                            Descripción
                                        </label>
                                        <p className="mt-1 text-slate-700 dark:text-slate-300 bg-slate-50 dark:bg-slate-800/50 p-3 rounded-lg">
                                            {enfoquePedagogico.description}
                                        </p>
                                    </div>
                                )}

                                <div className="grid grid-cols-2 gap-4">
                                    <div>
                                        <label className="text-sm font-medium text-slate-900 dark:text-white">
                                            Fecha de Creación
                                        </label>
                                        <p className="mt-1 text-slate-700 dark:text-slate-300 bg-slate-50 dark:bg-slate-800/50 p-3 rounded-lg">
                                            {new Date(enfoquePedagogico.created_at).toLocaleDateString('es-ES', {
                                                year: 'numeric',
                                                month: 'long',
                                                day: 'numeric',
                                                hour: '2-digit',
                                                minute: '2-digit'
                                            })}
                                        </p>
                                    </div>
                                    <div>
                                        <label className="text-sm font-medium text-slate-900 dark:text-white">
                                            Última Actualización
                                        </label>
                                        <p className="mt-1 text-slate-700 dark:text-slate-300 bg-slate-50 dark:bg-slate-800/50 p-3 rounded-lg">
                                            {new Date(enfoquePedagogico.updated_at).toLocaleDateString('es-ES', {
                                                year: 'numeric',
                                                month: 'long',
                                                day: 'numeric',
                                                hour: '2-digit',
                                                minute: '2-digit'
                                            })}
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </CardContent>
                    </Card>
                </div>
            </div>
        </AppLayout>
    );
}
