'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 { useAlertas, useAlertasStats, useUpdateAlerta, useDeleteAlerta, useMarkAllAsRead } from '@/lib/hooks/use-alertas'; import { Bell, Check, Trash2, AlertTriangle, Info, AlertCircle, CheckCircle } from 'lucide-react'; import { cn } from '@/lib/utils'; const prioridadStyles = { alta: 'border-l-4 border-l-destructive bg-destructive/5', media: 'border-l-4 border-l-warning bg-warning/5', baja: 'border-l-4 border-l-muted bg-muted/5', }; const prioridadIcons = { alta: AlertCircle, media: AlertTriangle, baja: Info, }; export default function AlertasPage() { const [filter, setFilter] = useState<'todas' | 'pendientes' | 'resueltas'>('pendientes'); const { data: alertas, isLoading } = useAlertas({ resuelta: filter === 'resueltas' ? true : filter === 'pendientes' ? false : undefined, }); const { data: stats } = useAlertasStats(); const updateAlerta = useUpdateAlerta(); const deleteAlerta = useDeleteAlerta(); const markAllAsRead = useMarkAllAsRead(); const handleMarkAsRead = (id: number) => { updateAlerta.mutate({ id, data: { leida: true } }); }; const handleResolve = (id: number) => { updateAlerta.mutate({ id, data: { resuelta: true } }); }; const handleDelete = (id: number) => { if (confirm('¿Eliminar esta alerta?')) { deleteAlerta.mutate(id); } }; return (
{/* Stats */}
Total
{stats?.total || 0}
No Leidas
{stats?.noLeidas || 0}
Alta Prioridad
{stats?.alta || 0}
Pendientes
{(stats?.alta || 0) + (stats?.media || 0) + (stats?.baja || 0)}
{/* Filters */}
{/* Alertas List */}
{isLoading ? (
Cargando...
) : alertas?.length === 0 ? (

No hay alertas {filter === 'pendientes' ? 'pendientes' : ''}

) : ( alertas?.map((alerta) => { const Icon = prioridadIcons[alerta.prioridad]; return (

{alerta.titulo}

{!alerta.leida && ( Nueva )}

{alerta.mensaje}

{new Date(alerta.createdAt).toLocaleDateString('es-MX')} {alerta.fechaVencimiento && ( Vence: {new Date(alerta.fechaVencimiento).toLocaleDateString('es-MX')} )}
{!alerta.leida && ( )} {!alerta.resuelta && ( )}
); }) )}
); }