import { getTranslations, getCurrentLocale } from '@/lib/i18n';
import { PurchaseCreditNotesClient } from '../../../../../components/admin/purchase-credit-notes-client';
import { getCurrencySymbolAsync } from '@/lib/server-currency';

export default async function CreditNotesHistoryPage() {
  const locale = await getCurrentLocale();
  const t = getTranslations(locale);
  const tPurchases = t.Purchases ?? {};

  const { pgGetPurchaseCreditNotes, pgGetPurchaseOrders, pgGetSuppliers } = await import('@/lib/postgres/data-access');
  const [creditResult, invoiceResult, suppliersResult] = await Promise.all([
    pgGetPurchaseCreditNotes({ page: 1, pageSize: 5000 }),
    pgGetPurchaseOrders({ page: 1, pageSize: 5000 }),
    pgGetSuppliers({ page: 1, pageSize: 5000 }),
  ]);

  const creditNotes = creditResult.items || [];
  const invoices = invoiceResult.items || [];
  const suppliers = suppliersResult.items || [];
  const currencySymbol = await getCurrencySymbolAsync();

  return (
    <PurchaseCreditNotesClient
      creditNotes={creditNotes}
      invoices={invoices}
      suppliers={suppliers}
      t={tPurchases}
      currencySymbol={currencySymbol}
      showCreateButton={false}
    />
  );
}