require("../../../_virtual/_rolldown/runtime.js");
const require_locale = require("../../../utils/locale.js");
const require_locales = require("../locales.js");
const require_utils = require("../../translation/utils.js");
let _pisell_utils = require("@pisell/utils");
//#region src/components/pisellFloorMapLayout/utils/floorMapCanvasDisplay.ts
/**
* 合并平面图 Tab 用多语言包（与业务侧 `locales.init` 可叠加）。
*/
function initFloorMapLayoutLocales(engineLocale) {
	_pisell_utils.locales.init(require_locales.default, engineLocale);
}
/** 与 List / 预约等物料一致：storage → 宿主 getLocale → native_locale → materials 当前语言 */
function getFloorMapDisplayLocale(engineCtx) {
	var _appHelper, _utils$storage, _utils$storage$get, _utils$getApp, _utils$getApp$getLoca;
	const utils = engineCtx === null || engineCtx === void 0 || (_appHelper = engineCtx.appHelper) === null || _appHelper === void 0 ? void 0 : _appHelper.utils;
	const fromStorage = utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 || (_utils$storage$get = _utils$storage.get) === null || _utils$storage$get === void 0 ? void 0 : _utils$storage$get.call(_utils$storage, "umi_locale");
	if (typeof fromStorage === "string" && fromStorage.trim()) return fromStorage;
	const fromApp = utils === null || utils === void 0 || (_utils$getApp = utils.getApp) === null || _utils$getApp === void 0 || (_utils$getApp = _utils$getApp.call(utils)) === null || _utils$getApp === void 0 || (_utils$getApp = _utils$getApp.locales) === null || _utils$getApp === void 0 || (_utils$getApp$getLoca = _utils$getApp.getLocale) === null || _utils$getApp$getLoca === void 0 ? void 0 : _utils$getApp$getLoca.call(_utils$getApp);
	if (typeof fromApp === "string" && fromApp.trim()) return fromApp;
	if (typeof localStorage !== "undefined") {
		const native = localStorage.getItem("CapacitorStorage.native_locale");
		if (native && native.trim()) return native;
	}
	return require_locale.getCurrentLocale();
}
/**
* 按当前语言（或显式传入语言）从平面图语言包取文案，**不依赖全局激活语言**
* （避免多组件 init 竞态），缺失时回退英文，再回退 key 本身。
*/
function getFloorMapLayoutText(id, displayLocale) {
	var _ref, _ref2, _ref3, _ref4, _maps$lang$id, _maps$lang, _maps$zhCN, _maps$zh, _maps$zhHK, _maps$en;
	const lang = _pisell_utils.locales.formatLocale(displayLocale || require_locale.getCurrentLocale());
	const maps = require_locales.default;
	return (_ref = (_ref2 = (_ref3 = (_ref4 = (_maps$lang$id = (_maps$lang = maps[lang]) === null || _maps$lang === void 0 ? void 0 : _maps$lang[id]) !== null && _maps$lang$id !== void 0 ? _maps$lang$id : (_maps$zhCN = maps["zh-CN"]) === null || _maps$zhCN === void 0 ? void 0 : _maps$zhCN[id]) !== null && _ref4 !== void 0 ? _ref4 : (_maps$zh = maps.zh) === null || _maps$zh === void 0 ? void 0 : _maps$zh[id]) !== null && _ref3 !== void 0 ? _ref3 : (_maps$zhHK = maps["zh-HK"]) === null || _maps$zhHK === void 0 ? void 0 : _maps$zhHK[id]) !== null && _ref2 !== void 0 ? _ref2 : (_maps$en = maps.en) === null || _maps$en === void 0 ? void 0 : _maps$en[id]) !== null && _ref !== void 0 ? _ref : id;
}
const I18N_LOCALE_ORDER = [
	"en",
	"zh-CN",
	"zh-HK",
	"ja",
	"pt"
];
/**
* 引擎 locale 与画布 name 对象字段对齐（如 en-US → en、zh_CN → zh-CN）。
*/
function localeKeysToTryForCanvasName(engineLocale) {
	const out = [];
	const push = (k) => {
		if (!out.includes(k)) out.push(k);
	};
	push(engineLocale);
	if (engineLocale === "en-US" || engineLocale === "en-GB") push("en");
	if (engineLocale === "zh_CN" || engineLocale === "zh") push("zh-CN");
	for (const k of I18N_LOCALE_ORDER) push(k);
	return out;
}
/**
* 从多语言对象中取当前 locale 下展示字符串，缺省按 en → 其余首个非空。
*/
function pickFloorMapCanvasI18nString(obj, engineLocale) {
	for (const loc of localeKeysToTryForCanvasName(engineLocale)) {
		const v = obj[loc];
		if (typeof v === "string" && v.trim()) return v.trim();
	}
	for (const v of Object.values(obj)) if (typeof v === "string" && v.trim()) return v.trim();
	return "";
}
function isCanvasNameI18nObject(n) {
	if (!n || typeof n !== "object" || Array.isArray(n)) return false;
	const o = n;
	for (const k of I18N_LOCALE_ORDER) if (typeof o[k] === "string") return true;
	return false;
}
/**
* 画布在 Tab / 下拉中的展示名：
* 1. `name` 为多语言对象时 **优先** 按引擎 locale 取字段（与配置内嵌文案一致）；
* 2. 否则 `nameKey` + `locales.getText`（需业务侧已 init 对应语言包）；
* 3. 否则 `name` 字符串。
*/
function getFloorMapCanvasDisplayName(canvas, engineLocale) {
	initFloorMapLayoutLocales(engineLocale);
	const n = canvas.name;
	if (isCanvasNameI18nObject(n)) {
		const fromObj = pickFloorMapCanvasI18nString(n, engineLocale);
		if (fromObj) return fromObj;
	}
	if (canvas.nameKey) {
		const t = _pisell_utils.locales.getText(canvas.nameKey);
		if (t !== canvas.nameKey) return t;
	}
	if (typeof n === "string") return n;
	if (n && typeof n === "object" && !Array.isArray(n)) return pickFloorMapCanvasI18nString(n, engineLocale);
	return "";
}
/**
* 打开重命名弹层时的初始多语言值（与 Translation 表单一致）。
*/
function seedFloorMapCanvasNameI18n(canvas, displayFallback) {
	const n = canvas.name;
	if (n && typeof n === "object") {
		var _n$en, _n$zhCN, _n$zhHK, _n$ja, _n$pt;
		return {
			en: (_n$en = n.en) !== null && _n$en !== void 0 ? _n$en : "",
			"zh-CN": (_n$zhCN = n["zh-CN"]) !== null && _n$zhCN !== void 0 ? _n$zhCN : "",
			"zh-HK": (_n$zhHK = n["zh-HK"]) !== null && _n$zhHK !== void 0 ? _n$zhHK : "",
			ja: (_n$ja = n.ja) !== null && _n$ja !== void 0 ? _n$ja : "",
			pt: (_n$pt = n.pt) !== null && _n$pt !== void 0 ? _n$pt : ""
		};
	}
	return require_utils.createTranslationText(typeof n === "string" && n.trim() ? n.trim() : displayFallback, true);
}
//#endregion
exports.getFloorMapCanvasDisplayName = getFloorMapCanvasDisplayName;
exports.getFloorMapDisplayLocale = getFloorMapDisplayLocale;
exports.getFloorMapLayoutText = getFloorMapLayoutText;
exports.initFloorMapLayoutLocales = initFloorMapLayoutLocales;
exports.seedFloorMapCanvasNameI18n = seedFloorMapCanvasNameI18n;
