import { verifySession } from '@/lib/auth';
import { hasEmployeePermission } from '@/lib/employee-permissions';
import { getCurrentLocale, getTranslations } from '@/lib/i18n';
import { BankReconciliationManager } from '@/components/admin/bank-reconciliation-manager';

export default async function BankReconciliationPage() {
  const session = await verifySession();
  const user = session.user;
  const locale = await getCurrentLocale();
  const t = getTranslations(locale);
  const settings = await (await import('@/lib/postgres/data-access')).pgGetSettings();

  if (!user || !hasEmployeePermission(user, settings, 'admin.accounting')) {
    return (
      <div className="text-center">
        <h1 className="text-2xl font-bold">{t.Global.accessDenied}</h1>
        <p>{t.Global.noPermission}</p>
      </div>
    );
  }

  const matchedBy = String((user as any)?.email || user.name || user.id || 'system');

  return (
    <div className="p-6 space-y-6">
      <div>
        <h1 className="text-3xl font-bold">التسوية البنكية</h1>
        <p className="text-muted-foreground mt-1">لوحة إدارة كاملة لاستيراد كشف البنك، المعاينة، والتطبيق النهائي للتسوية.</p>
      </div>
      <BankReconciliationManager defaultMatchedBy={matchedBy} />
    </div>
  );
}
