import DashboardLayout from '@/components/layout/dashboard-layout';
import { verifySession } from '@/lib/auth';
import { hasEmployeePermission } from '@/lib/employee-permissions';
import { getCurrentLocale } from '@/lib/i18n';
import { pgGetSettings } from '@/lib/postgres/data-access';
import BiometricDevicesManager from '@/components/admin/biometric-devices-manager';

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

  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>locale={locale} 
      <BiometricDevicesManager initialTab='devices' hideTabs />
    </DashboardLayout>
  );
}
