import { redirect } from 'next/navigation';
import { getSession } from '@/lib/auth';
import { handleListSalesInvoices } from '@/lib/actions/sales-invoice.actions';
import SalesDebitNotesClient from '@/components/admin/sales/sales-debit-notes-client';

export const metadata = { title: 'إذونات التخفيض' };

export default async function DebitNotesPage() {
  const session = await getSession();
  if (!session?.user) {
    redirect('/login');
  }

  const result = await handleListSalesInvoices({ take: 300 });
  const invoices = result.success ? result.data?.items || [] : [];

  return (
    <SalesDebitNotesClient
      invoices={invoices}
      userId={session.user.id}
      userName={session.user.name}
    />
  );
}
