import { verifySession } from "@/lib/auth";
import { hasEmployeePermission } from "@/lib/employee-permissions";
import { getCurrentLocale, getTranslations } from "@/lib/i18n";
import PermissionsProfilesManager from "@/components/admin/permissions-profiles-manager";

export default async function PermissionsManagementPage() {
  const session = await verifySession();
  const user = session.user;
  const locale = await getCurrentLocale();
  const t = getTranslations(locale);
  const tGlobal = t.Global || {};

  const settings = await (await import("@/lib/postgres/data-access")).pgGetSettings();
  if (!user || !hasEmployeePermission(user, settings, "settings.manage")) {
    return (
      <div className="text-center">
        <h1 className="text-2xl font-bold">{tGlobal?.accessDenied ?? "الوصول مرفوض"}</h1>
        <p>{tGlobal?.noPermission ?? "ليس لديك صلاحية لعرض هذه الصفحة."}</p>
      </div>
    );
  }

  return (
    <PermissionsProfilesManager
      currentSettings={settings}
      tGlobal={tGlobal}
    />
  );
}
