import { AdvancedChecksAnalytics } from '@/components/admin/advanced-checks-analytics';
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 AdvancedAnalyticsPage() {
  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 || []);

  const analyticsText = (t as any)?.AdvancedAnalytics || {};

  return (
    <DashboardLayout>
      <div className="space-y-6">
        <div>
          <h1 className="text-2xl font-bold tracking-tight">{analyticsText.title ?? 'تحليل الشيكات المتقدم'}</h1>
          <p className="text-sm text-muted-foreground">
            {analyticsText.description ?? 'تحليلات شاملة لحركة الشيكات والتجيير والالتزامات المالية.'}
          </p>
        </div>
        <AdvancedChecksAnalytics checks={checks as any[]} t={analyticsText} currencySymbol={currencySymbol} />
      </div>
    </DashboardLayout>
  );
}
