import { NextResponse } from "next/server";
import { z } from "zod";
import { resolveTranslationsRouteContext } from "@open-mercato/core/modules/translations/api/context";
import { isCrudHttpError } from "@open-mercato/shared/lib/crud/errors";
import { locales as defaultLocales } from "@open-mercato/shared/lib/i18n/config";
import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("translations").child({ component: "locales" });
const metadata = {
  path: "/translations/locales",
  GET: { requireAuth: true, requireFeatures: ["translations.view"] }
};
async function GET(req) {
  try {
    const context = await resolveTranslationsRouteContext(req);
    const configService = context.container.resolve("moduleConfigService");
    const locales = await configService.getValue("translations", "supported_locales", {
      defaultValue: [...defaultLocales],
      scope: { tenantId: context.tenantId }
    });
    return NextResponse.json({ locales: Array.isArray(locales) ? locales : [...defaultLocales] });
  } catch (err) {
    if (isCrudHttpError(err)) {
      return NextResponse.json(err.body, { status: err.status });
    }
    logger.error("Failed to load locales", { err });
    return NextResponse.json({ error: "Internal server error" }, { status: 500 });
  }
}
const responseSchema = z.object({
  locales: z.array(z.string())
});
const getDoc = {
  summary: "List supported translation locales",
  tags: ["Translations"],
  responses: [
    { status: 200, description: "Supported locales list", schema: responseSchema }
  ]
};
const openApi = {
  tag: "Translations",
  summary: "List supported translation locales",
  methods: {
    GET: getDoc
  }
};
var locales_default = GET;
export {
  locales_default as default,
  metadata,
  openApi
};
//# sourceMappingURL=locales.js.map
