import DashboardLayout from '@/components/layout/dashboard-layout';
import { verifySession } from '@/lib/auth';
import { hasEmployeePermission } from '@/lib/employee-permissions';
import { pgGetSettings } from '@/lib/postgres/data-access';
import AttendanceReportsManager from '@/components/admin/attendance-reports-manager';

export default async function HRAttendanceReportsPage() {
  const session = await verifySession();
  if (!session?.user) return null;

  const settings = await pgGetSettings();

  const canAccess =
    hasEmployeePermission(session.user, settings, 'admin.hr-attendance') ||
    hasEmployeePermission(session.user, settings, 'admin.employees');

  if (!canAccess) {
    return (
      <DashboardLayout>
        <div className="text-center">
          <h1 className="text-2xl font-bold">غير مصرح</h1>
          <p>لا تملك صلاحية الوصول إلى تقارير الحضور.</p>
        </div>
      </DashboardLayout>
    );
  }

  return (
    <DashboardLayout>
      <AttendanceReportsManager />
    </DashboardLayout>
  );
}
