import { defineComponent as k, mergeModels as T, useModel as A, onBeforeMount as F, watch as d, createElementBlock as B, createCommentVNode as S, openBlock as V, Fragment as N, createVNode as p, unref as r } from "vue";
import { useI18n as K } from "vue-i18n";
import { storeToRefs as M } from "pinia";
import { a_ as y } from "./start-CE9SawgU.js";
import "./header-Bn1EKnBE.js";
import { u as h } from "./dictionary-B08TTkmv.js";
import { b as m } from "./rma-address-field-extension.json_vue_type_i18n_index_0_src_true_lang-B0T8WrmL.js";
const x = /* @__PURE__ */ k({
  __name: "RMAAddressFieldExtension",
  props: /* @__PURE__ */ T({
    attributeMap: {},
    destinationAttribute: {},
    sourceAttributes: {},
    etlAttributeSetMapId: {}
  }, {
    modelValue: {},
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(f) {
    const a = A(f, "modelValue"), { t } = K(), n = h(), { addressTypes: o, isAddressTypesLoading: v } = M(n);
    F(() => {
      n.ensureAddressTypes();
    });
    const c = [
      "reference",
      "paymentType",
      "sourceBusinessDocumentId",
      "sourceBusinessDocumentNumber",
      "trackingNumbers",
      "trackingLinks",
      "comment",
      "created",
      "returnsCnt"
    ];
    function u(e) {
      return typeof e == "string" || e && typeof e == "object" && !("key" in e) && !("typeKey" in e);
    }
    function b(e) {
      return Array.isArray(e) ? e.map((l) => {
        if (!l)
          return null;
        if (typeof l == "object") {
          if ("key" in l && "value" in l)
            return {
              typeKey: String(l.key),
              typeName: String(l.value) || String(l.key)
            };
          if ("typeKey" in l && "typeName" in l)
            return {
              typeKey: String(l.typeKey),
              typeName: String(l.typeName)
            };
        }
        return {
          typeKey: String(l),
          typeName: String(l)
        };
      }).filter(Boolean) : [];
    }
    function g(e) {
      if (typeof e == "string")
        return { key: e, value: e };
      if (e && typeof e == "object") {
        const l = e.key || e.field || e.name;
        return l ? {
          key: l,
          value: e.value || e.label || l
        } : null;
      }
      return null;
    }
    return d(
      a,
      (e) => {
        e?.availableFields?.length || (a.value = {
          ...a.value,
          availableFields: c.map((i) => ({
            key: i,
            value: t(`rma-plugin.rma-field-extension.${i}`)
          }))
        }), e?.addressTypes?.length || (a.value = {
          ...a.value,
          addressTypes: o.value ?? []
        }), a.value?.availableFields?.some(u) && (a.value = {
          ...a.value,
          availableFields: a.value?.availableFields?.map(g)?.filter(Boolean) ?? []
        }), a.value?.addressTypes?.some(u) && (a.value = {
          ...a.value,
          addressTypes: b(
            a.value?.addressTypes ?? []
          )
        });
      },
      { immediate: !0 }
    ), d(
      o,
      (e) => {
        a.value?.addressTypes?.length || (a.value = {
          ...a.value,
          addressTypes: e ?? []
        });
      },
      { immediate: !0 }
    ), (e, l) => a.value ? (V(), B(N, { key: 0 }, [
      p(r(y), {
        modelValue: a.value.type,
        "onUpdate:modelValue": l[0] || (l[0] = (s) => a.value.type = s),
        items: a.value.addressTypes ?? [],
        label: r(t)("rma-plugin.rma-address-field-extension.addressTypes"),
        loading: r(v),
        "item-title": "typeName",
        "item-value": "typeKey"
      }, null, 8, ["modelValue", "items", "label", "loading"]),
      p(r(y), {
        modelValue: a.value.field,
        "onUpdate:modelValue": l[1] || (l[1] = (s) => a.value.field = s),
        items: a.value.availableFields ?? [],
        label: r(t)("rma-plugin.rma-email-address-extension.rmaField"),
        "item-title": "value",
        "item-value": "key"
      }, null, 8, ["modelValue", "items", "label"])
    ], 64)) : S("", !0);
  }
});
typeof m == "function" && m(x);
export {
  x as default
};
