import { getTranslations, getCurrentLocale } from '@/lib/i18n';
import PurchaseCreditNoteCreatePageClient from '../../../../../components/admin/purchase-credit-note-create-page-client';
import { getCurrencySymbolAsync } from '@/lib/server-currency';

export default async function NewCreditNotePage() {
  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 (
    <PurchaseCreditNoteCreatePageClient
      creditNotes={creditNotes}
      invoices={invoices}
      suppliers={suppliers}
      t={tPurchases}
      currencySymbol={currencySymbol}
    />
  );
}