import { defineComponent as _, mergeModels as M, useModel as T, ref as b, computed as N, watch as I, onBeforeMount as S, createElementBlock as U, openBlock as r, createBlock as c, createCommentVNode as k, unref as l, mergeProps as x, withCtx as p, createTextVNode as E, toDisplayString as B, createVNode as C } from "vue";
import { useI18n as D } from "vue-i18n";
import { ab as L, ac as w, j as P, a as $, d as V, o as j } from "./start-CE9SawgU.js";
import "pinia";
import "./header-Bn1EKnBE.js";
import { e as q, b as v } from "./unit-to-tree-node.json_vue_type_i18n_index_0_src_true_lang-C4C1UfLN.js";
import { a as F } from "./constants-DiSFhhBB.js";
import { b as H } from "./constants-CwfsvyFM.js";
const O = { class: "unit-wrapper" }, A = /* @__PURE__ */ _({
  __name: "MappingTableExtension",
  props: /* @__PURE__ */ M({
    attributeMap: {},
    destinationAttribute: {},
    sourceAttributes: {},
    etlAttributeSetMapId: {}
  }, {
    modelValue: { default: () => [] },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(m) {
    const o = m, e = T(m, "modelValue"), { t: i } = D(), g = L(), n = b([]), s = b(!1), y = N(
      () => o.sourceAttributes?.[0]?.dataType && H.includes(o.sourceAttributes?.[0]?.dataType)
    );
    function h() {
      e.value.push({
        destinationValue: null,
        sourceValue: {
          value: null,
          friendlyName: null
        }
      });
    }
    return I(
      () => o.sourceAttributes?.[0],
      async (d) => {
        if (e.value = [], n.value = [], !!d?.id)
          try {
            s.value = !0;
            const { destinationTreeOptions: u, mapping: t } = await q.getMappingTableETLExtensionData({
              sourceAttributeId: d.id,
              destinationAttributeId: o.destinationAttribute?.id,
              attributeMapId: o.attributeMap?.id,
              etlAttributeSetMapId: o.etlAttributeSetMapId
            });
            n.value = u?.map(({ destinationValue: a }) => a).filter(Boolean) ?? [], e.value = n.value.length ? t?.map(({ sourceValue: a, destinationValue: f }) => ({
              sourceValue: a,
              destinationValue: f ? Number(f) : null
            })) ?? [] : t;
          } catch (u) {
            console.error("Loading mapping table failed:", u), g.push({
              message: i("common.requestFailed"),
              type: w.error
            });
          } finally {
            s.value = !1;
          }
      },
      { immediate: !0 }
    ), S(() => {
      Array.isArray(e.value) || (e.value = []);
    }), (d, u) => (r(), U("div", O, [
      Array.isArray(e.value) ? (r(), c(l(P), x({
        key: 0,
        data: e.value,
        "create-actions": y.value,
        "is-loading": s.value
      }, l(F), { onCreate: h }), {
        "cell-source": p(({ rowIndex: t }) => [
          C(l(V), {
            modelValue: e.value[t].sourceValue.friendlyName,
            "onUpdate:modelValue": (a) => e.value[t].sourceValue.friendlyName = a,
            label: l(i)("datahub-plugin.etl.unit-to-tree-node.sourceValue"),
            "max-width": "567",
            "persistent-placeholder": "",
            readonly: ""
          }, null, 8, ["modelValue", "onUpdate:modelValue", "label"])
        ]),
        "cell-destination": p(({ rowIndex: t }) => [
          n.value.length ? (r(), c(l($), {
            key: 0,
            modelValue: e.value[t].destinationValue,
            "onUpdate:modelValue": (a) => e.value[t].destinationValue = a,
            items: n.value,
            label: l(i)("datahub-plugin.etl.unit-to-tree-node.destinationValue"),
            "max-width": "567",
            "item-title": "friendlyName",
            "persistent-placeholder": ""
          }, null, 8, ["modelValue", "onUpdate:modelValue", "items", "label"])) : (r(), c(l(V), {
            key: 1,
            modelValue: e.value[t].destinationValue,
            "onUpdate:modelValue": (a) => e.value[t].destinationValue = a,
            label: l(i)("datahub-plugin.etl.unit-to-tree-node.destinationValue"),
            "max-width": "567",
            "persistent-placeholder": ""
          }, null, 8, ["modelValue", "onUpdate:modelValue", "label"]))
        ]),
        "no-data-description": p(() => [
          E(B(l(i)("datahub-plugin.etl.unit-to-tree-node.SelectSourceAttribute")), 1)
        ]),
        _: 1
      }, 16, ["data", "create-actions", "is-loading"])) : k("", !0)
    ]));
  }
});
typeof v == "function" && v(A);
const X = /* @__PURE__ */ j(A, [["__scopeId", "data-v-def69dcd"]]);
export {
  X as default
};
