import { EndorsedChecksReport } from '@/components/admin/endorsed-checks-report';
import DashboardLayout from '@/components/layout/dashboard-layout';
import { getCurrentLocale, getTranslations } from '@/lib/i18n';
import { pgGetChecksReceived, pgGetSettings } from '@/lib/postgres/data-access';

export default async function EndorsedChecksPage() {
  const locale = await getCurrentLocale();
  const t = getTranslations(locale);
  const settings = await pgGetSettings();
  const currencySymbol = String(settings?.currency || settings?.appCurrency || '$');

  const checks = ((await pgGetChecksReceived({ page: 1, pageSize: 5000 })).items || [])
    .filter((check: any) => check.reservationStatus === 'endorsed' || check.endorsementStatus === 'endorsed-to-party');

  const endorsedChecksText = (t as any)?.EndorsedChecksReport || {};

  return (
    <DashboardLayout>
      <div className="space-y-6">
        <div>
          <h1 className="text-2xl font-bold tracking-tight">{endorsedChecksText.title ?? 'تقرير الشيكات المجيّرة'}</h1>
          <p className="text-sm text-muted-foreground">
            {endorsedChecksText.description ?? 'متابعة الشيكات المجيّرة للموردين وإحصائيات التجيير والالتزامات المالية.'}
          </p>
        </div>
        <EndorsedChecksReport checks={checks as any[]} t={endorsedChecksText} currencySymbol={currencySymbol} />
      </div>
    </DashboardLayout>
  );
}
