'use client' import { useState } from 'react' import { useFinanzasStore } from '@/lib/store' import { predictNextBill, calculateTrend } from '@/lib/predictions' import { formatCurrency } from '@/lib/utils' import { Zap, Droplets, Flame, Wifi, TrendingUp, TrendingDown, Plus, History } from 'lucide-react' import { cn } from '@/lib/utils' import { AddServiceModal } from '@/components/modals/AddServiceModal' const SERVICES = [ { id: 'electricity', label: 'Luz (Electricidad)', icon: Zap, color: 'text-yellow-400', bg: 'bg-yellow-400/10' }, { id: 'water', label: 'Agua', icon: Droplets, color: 'text-blue-400', bg: 'bg-blue-400/10' }, { id: 'gas', label: 'Gas', icon: Flame, color: 'text-orange-400', bg: 'bg-orange-400/10' }, { id: 'internet', label: 'Internet', icon: Wifi, color: 'text-cyan-400', bg: 'bg-cyan-400/10' }, ] export default function ServicesPage() { const serviceBills = useFinanzasStore((state) => state.serviceBills) const [isAddModalOpen, setIsAddModalOpen] = useState(false) return (
{/* Header */}

Servicios y Predicciones

Gestiona tus consumos de Luz, Agua y Gas.

{/* Service Cards */}
{SERVICES.map((service) => { const Icon = service.icon const prediction = predictNextBill(serviceBills, service.id as any) const trend = calculateTrend(serviceBills, service.id as any) const lastBill = serviceBills .filter(b => b.type === service.id) .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())[0] return (
{trend !== 0 && (
0 ? "bg-red-500/10 text-red-400" : "bg-emerald-500/10 text-emerald-400")}> {trend > 0 ? : } {Math.abs(trend).toFixed(0)}%
)}

{service.label}

{formatCurrency(prediction || (lastBill?.amount ?? 0))}

{prediction > 0 && (est.)}

{lastBill ? `Último: ${formatCurrency(lastBill.amount)}` : 'Sin historial'}

) })}
{/* History List */}

Historial de Pagos

{serviceBills.length === 0 ? (
No hay facturas registradas. Comienza agregando una para ver predicciones.
) : ( serviceBills .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) .map((bill) => { const service = SERVICES.find(s => s.id === bill.type) const Icon = service?.icon || Zap return (

{service?.label || bill.type}

{new Date(bill.date).toLocaleDateString('es-AR', { dateStyle: 'long' })}

{bill.usage && ( <>

Consumo: {bill.usage} {bill.unit}

)}

{formatCurrency(bill.amount)}

{bill.period}

{bill.usage && bill.amount && (

{formatCurrency(bill.amount / bill.usage)} / {bill.unit}

)}
) }) )}
setIsAddModalOpen(false)} />
) }