var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellFloorMapLayout/utils/floorMapCanvasDisplay.ts
var floorMapCanvasDisplay_exports = {};
__export(floorMapCanvasDisplay_exports, {
  getFloorMapCanvasDisplayName: () => getFloorMapCanvasDisplayName,
  initFloorMapLayoutLocales: () => initFloorMapLayoutLocales,
  pickFloorMapCanvasI18nString: () => pickFloorMapCanvasI18nString,
  seedFloorMapCanvasNameI18n: () => seedFloorMapCanvasNameI18n
});
module.exports = __toCommonJS(floorMapCanvasDisplay_exports);
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("../locales"));
var import_utils2 = require("../../translation/utils");
function initFloorMapLayoutLocales(engineLocale) {
  import_utils.locales.init(import_locales.default, engineLocale);
}
var I18N_LOCALE_ORDER = [
  "en",
  "zh-CN",
  "zh-HK",
  "ja",
  "pt"
];
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;
}
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;
}
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 = import_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 "";
}
function seedFloorMapCanvasNameI18n(canvas, displayFallback) {
  const n = canvas.name;
  if (n && typeof n === "object") {
    return {
      en: n.en ?? "",
      "zh-CN": n["zh-CN"] ?? "",
      "zh-HK": n["zh-HK"] ?? "",
      ja: n.ja ?? "",
      pt: n.pt ?? ""
    };
  }
  const s = typeof n === "string" && n.trim() ? n.trim() : displayFallback;
  return (0, import_utils2.createTranslationText)(s, true);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getFloorMapCanvasDisplayName,
  initFloorMapLayoutLocales,
  pickFloorMapCanvasI18nString,
  seedFloorMapCanvasNameI18n
});
