'use client'; import { useState } from 'react'; import { DashboardShell } from '@/components/layouts/dashboard-shell'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { useEventos, useUpdateEvento } from '@/lib/hooks/use-calendario'; import { Calendar, ChevronLeft, ChevronRight, Check, Clock, FileText, CreditCard } from 'lucide-react'; import { cn } from '@/lib/utils'; const meses = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']; const tipoIcons = { declaracion: FileText, pago: CreditCard, obligacion: Clock, custom: Calendar, }; const tipoColors = { declaracion: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200', pago: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200', obligacion: 'bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200', custom: 'bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200', }; export default function CalendarioPage() { const [año, setAño] = useState(new Date().getFullYear()); const [mes, setMes] = useState(new Date().getMonth() + 1); const { data: eventos, isLoading } = useEventos(año, mes); const updateEvento = useUpdateEvento(); const handlePrevMonth = () => { if (mes === 1) { setMes(12); setAño(año - 1); } else { setMes(mes - 1); } }; const handleNextMonth = () => { if (mes === 12) { setMes(1); setAño(año + 1); } else { setMes(mes + 1); } }; const handleToggleComplete = (id: number, completado: boolean) => { updateEvento.mutate({ id, data: { completado: !completado } }); }; // Generate calendar days const firstDay = new Date(año, mes - 1, 1).getDay(); const daysInMonth = new Date(año, mes, 0).getDate(); const days = Array.from({ length: 42 }, (_, i) => { const day = i - firstDay + 1; if (day < 1 || day > daysInMonth) return null; return day; }); const getEventosForDay = (day: number) => { return eventos?.filter(e => { const fecha = new Date(e.fechaLimite); return fecha.getDate() === day; }) || []; }; return (
{/* Calendar */} {meses[mes - 1]} {año}
{['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'].map(d => (
{d}
))} {days.map((day, i) => { const dayEventos = day ? getEventosForDay(day) : []; const isToday = day === new Date().getDate() && mes === new Date().getMonth() + 1 && año === new Date().getFullYear(); return (
{day && ( <>
{day}
{dayEventos.slice(0, 2).map(e => { const Icon = tipoIcons[e.tipo]; return (
{e.titulo}
); })} {dayEventos.length > 2 && (
+{dayEventos.length - 2} más
)}
)}
); })}
{/* Event List */} Eventos del Mes {isLoading ? (
Cargando...
) : eventos?.length === 0 ? (
No hay eventos este mes
) : (
{eventos?.map(evento => { const Icon = tipoIcons[evento.tipo]; return (

{evento.titulo}

{evento.descripcion}

{new Date(evento.fechaLimite).toLocaleDateString('es-MX', { day: 'numeric', month: 'short', })}

); })}
)}
); }