import Link from 'next/link'; import { Landmark, Plus } from 'lucide-react'; import { getTranslations } from 'next-intl/server'; import { createFinanceApi } from '@kit/finance/api'; import { formatDate } from '@kit/shared/dates'; import { getSupabaseServerClient } from '@kit/supabase/server-client'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { AccountNotFound } from '~/components/account-not-found'; import { CmsPageShell } from '~/components/cms-page-shell'; import { EmptyState } from '~/components/empty-state'; import { BATCH_STATUS_VARIANT, BATCH_STATUS_LABEL_KEYS } from '~/lib/status-badges'; interface PageProps { params: Promise<{ account: string }>; } const formatCurrency = (amount: unknown) => new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format( Number(amount), ); export default async function SepaPage({ params }: PageProps) { const { account } = await params; const client = getSupabaseServerClient(); const t = await getTranslations('finance'); const { data: acct } = await client .from('accounts') .select('id') .eq('slug', account) .single(); if (!acct) return ; const api = createFinanceApi(client); const batchesResult = await api.listBatches(acct.id); const batches = batchesResult.data; return (
{/* Header */}

Lastschrifteinzüge verwalten

{/* Table or Empty State */} {batches.length === 0 ? ( } title={t('sepa.noBatches')} description={t('sepa.createFirst')} actionLabel={t('nav.newBatch')} actionHref={`/home/${account}/finance/sepa/new`} /> ) : ( {t('sepa.title')} ({batches.length})
{batches.map((batch: Record) => ( ))}
{t('common.status')} {t('common.type')} {t('common.description')} {t('sepa.totalAmount')} {t('sepa.itemCount')} {t('sepa.executionDate')}
{t(BATCH_STATUS_LABEL_KEYS[String(batch.status)] ?? String(batch.status))} {batch.batch_type === 'direct_debit' ? t('sepa.directDebit') : t('sepa.creditTransfer')} {String(batch.description ?? '—')} {batch.total_amount != null ? formatCurrency(batch.total_amount) : '—'} {String(batch.item_count ?? 0)} {formatDate(batch.execution_date as string | null)}
)}
); }