"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadCommandLocale = loadCommandLocale;
exports.loadRawCommandLocale = loadRawCommandLocale;
const promises_1 = require("node:fs/promises");
const control_plane_config_1 = require("../config/control-plane-config");
const catalog_1 = require("../i18n/catalog");
async function loadCommandLocale(cwd) {
    if (!cwd) {
        return catalog_1.DEFAULT_APP_LOCALE;
    }
    try {
        return (await (0, control_plane_config_1.loadConfig)(cwd)).i18n.defaultLanguage;
    }
    catch {
        return catalog_1.DEFAULT_APP_LOCALE;
    }
}
async function loadRawCommandLocale(cwd) {
    if (!cwd) {
        return catalog_1.DEFAULT_APP_LOCALE;
    }
    try {
        const parsed = JSON.parse(await (0, promises_1.readFile)((0, control_plane_config_1.getConfigPath)(cwd), "utf8"));
        const defaultLanguage = parsed.i18n?.defaultLanguage;
        return (0, catalog_1.isAppLocale)(defaultLanguage) ? defaultLanguage : catalog_1.DEFAULT_APP_LOCALE;
    }
    catch {
        return catalog_1.DEFAULT_APP_LOCALE;
    }
}
