'use client'; import type { Direction, DocStatus } from '@impuestos/contracts'; import { formatGs, type Locale } from '@impuestos/i18n'; import { useQuery } from '@tanstack/react-query'; import { FileText } from 'lucide-react'; import { useState } from 'react'; import { DocCard } from '@/components/doc-card'; 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'; import { cn } from '@/lib/utils'; /** Flow E1: filterable list with a monthly total header. */ export function DocumentsScreen({ locale }: { locale: string }) { const t = useT(); const [direction, setDirection] = useState(); const [status, setStatus] = useState(); const [search, setSearch] = useState(''); const query = { ...(direction ? { direction } : {}), ...(status ? { status } : {}), ...(search.trim() ? { q: search.trim() } : {}), }; const documents = useQuery({ queryKey: ['documents', query], queryFn: ({ signal }) => api.listDocuments(query, signal), }); const items = documents.data?.items ?? []; const total = items.reduce((sum, doc) => sum + (doc.direction === 'purchase' ? doc.total : 0), 0); const errors = useQuery({ queryKey: ['documents', 'errors'], queryFn: ({ signal }) => api.listIngestErrors(signal), }); return (
{/* No scan button here: the shell carries a persistent one on every screen. */}

{t('docs.title')}

setSearch(event.target.value)} className="h-11 w-full rounded-2xl border bg-[var(--surface-raised)] px-4" />
{ setDirection(undefined); setStatus(undefined); }} /> setDirection(direction === 'purchase' ? undefined : 'purchase')} /> setDirection(direction === 'sale' ? undefined : 'sale')} /> setStatus(status === 'needs_review' ? undefined : 'needs_review')} />
{errors.data && errors.data.length > 0 ? (

{t('docs.errors.title')}

    {errors.data.map((error) => (
  • {error.message}
  • ))}
{t('docs.errors.retry')}
) : null} {documents.isPending ? ( ) : null} {documents.isError ? (

{t('common.error.generic')}

) : null} {documents.data && items.length === 0 ? ( } title={t('docs.empty')} action={ {t('docs.emptyCta')} } /> ) : null} {items.length > 0 ? ( <>

{t('docs.monthTotal')}

{formatGs(total)}

{t('docs.count', { count: documents.data?.total ?? items.length })}

    {items.map((document) => (
  • ))}
) : null}
); } function Filter({ label, active, onClick, }: { label: string; active: boolean; onClick: () => void; }) { return ( ); }