import { f as defineAdminEventHandler, W as requireAdminAuth, c as createError, a5 as isMfaEnabledGlobally, a7 as isMfaRequiredForRole, a6 as getAdminMfaState, ae as getAdminScopesForRole, af as getStepUpMaxAgeSeconds } from '../../../../nitro/nitro.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';

const me_get = defineAdminEventHandler("admin:auth:me", async (event) => {
  var _a;
  try {
    await requireAdminAuth(event);
    const adminUser = event.context.adminUser;
    if (!adminUser) {
      throw createError({
        statusCode: 401,
        statusMessage: "Unauthorized",
        message: "Admin user not found in context"
      });
    }
    const globallyEnabled = isMfaEnabledGlobally();
    const required = globallyEnabled && isMfaRequiredForRole(adminUser.role);
    const state = globallyEnabled ? await getAdminMfaState(adminUser.id) : null;
    const adminScopes = await getAdminScopesForRole(adminUser.role);
    const jwtCtx = event.context.adminJwt;
    const stepUpMaxAge = getStepUpMaxAgeSeconds();
    const now = Math.floor(Date.now() / 1e3);
    const stepUpFresh = Boolean(state == null ? void 0 : state.enabled) && Boolean(jwtCtx == null ? void 0 : jwtCtx.amr.includes("mfa")) && typeof (jwtCtx == null ? void 0 : jwtCtx.mvAt) === "number" && now - jwtCtx.mvAt < stepUpMaxAge;
    return {
      success: true,
      data: {
        user: { ...adminUser, adminScopes },
        mfa: {
          globallyEnabled,
          required,
          enabled: Boolean(state == null ? void 0 : state.enabled),
          enrollmentRequired: required && !(state == null ? void 0 : state.enabled),
          recoveryCodesRemaining: (_a = state == null ? void 0 : state.recoveryHashes.length) != null ? _a : 0,
          stepUpFresh,
          stepUpMaxAgeSeconds: stepUpMaxAge
        }
      }
    };
  } catch (error) {
    if (error && typeof error === "object" && "statusCode" in error) {
      throw error;
    }
    console.error("[GET /api/admin/auth/me] Error:", error);
    throw createError({
      statusCode: 500,
      statusMessage: "Failed to get admin profile",
      message: error instanceof Error ? error.message : "Unknown error"
    });
  }
});

export { me_get as default };
//# sourceMappingURL=me.get.mjs.map
