import { useI18n } from "vue-i18n";

/**
 * Etiquetas en español para códigos de área TIBU (`lavanderia.area.codes.*`).
 */
export function useAreaLabel() {
  const { t, te } = useI18n();

  function areaLabelFromCode(code) {
    if (code == null || code === "") return "—";
    const key = `lavanderia.area.codes.${code}`;
    return te(key) ? t(key) : String(code);
  }

  /** @param {{ code?: string, name?: string }|string|null|undefined} areaOrCode */
  function areaDisplayLine(areaOrCode) {
    if (areaOrCode == null || areaOrCode === "") return "—";
    if (typeof areaOrCode === "object") {
      const fromCode = areaOrCode.code ? areaLabelFromCode(areaOrCode.code) : null;
      if (fromCode && fromCode !== areaOrCode.code) return fromCode;
      return areaOrCode.name || fromCode || "—";
    }
    return areaLabelFromCode(areaOrCode);
  }

  return { areaLabelFromCode, areaDisplayLine };
}
