'use client';
import type { DashboardDto } from '@impuestos/contracts';
import { formatDateLong, formatGs, formatGsAmount, formatMonthName, type Locale } from '@impuestos/i18n';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { ScanLine, X } from 'lucide-react';
import { TraceableNumber } from '@/components/traceable-number';
import { Button, buttonClasses } from '@/components/ui/button';
import { Card } from '@/components/ui/card';
import { EmptyState } from '@/components/ui/empty-state';
import { Skeleton } from '@/components/ui/skeleton';
import { Link } from '@/i18n/navigation';
import { useT } from '@/i18n/t';
import { api } from '@/lib/api';
/** Flow C: position header, then exactly one next action, then the insight feed. */
export function Dashboard({ locale, fullName }: { locale: Locale; fullName: string }) {
const t = useT();
const dashboard = useQuery({
queryKey: ['dashboard'],
queryFn: ({ signal }) => api.getDashboard(signal),
});
if (dashboard.isPending) {
return (
);
}
if (dashboard.isError || !dashboard.data) {
return (
{t('common.error.generic')}
);
}
const data = dashboard.data;
// Flow A6: until the first comprobante arrives there is nothing to show but the way in.
const nothingYet = !data.hasDocuments;
return (
{t('home.title')}
{fullName}
{nothingYet ? (
}
title={t('home.firstRun.title')}
body={t('home.noPosition')}
action={
{t('home.firstRun.scan')}
}
/>
) : null}
{!nothingYet ? (
<>
{/* Zone 1: the position, one card per obligation, swipeable on a phone. */}
{data.iva ? : null}
{data.irp ? : null}
{/* Zone 2: exactly one next action. */}
{/* Zone 3: the insight feed. */}
>
) : null}