import { defineComponent as h, mergeModels as T, useModel as I, ref as b, computed as N, watch as E, onBeforeMount as S, createElementBlock as x, openBlock as v, createBlock as U, createCommentVNode as k, unref as o, mergeProps as B, withCtx as p, createTextVNode as C, toDisplayString as D, createVNode as V } from "vue";
import { useI18n as L } from "vue-i18n";
import { i as w, h as P, b as R, l as $ } from "./start-BYfL32Oe.mjs";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { e as H, b as _ } from "./unit-to-tree-node.json_vue_type_i18n_index_0_src_true_lang-DwzUuppf.mjs";
import { a as Y } from "./constants--S2sBPny.mjs";
import { b as j } from "./constants-CwfsvyFM.mjs";
const q = { class: "unit-wrapper" }, A = /* @__PURE__ */ h({
  __name: "MappingTableExtension",
  props: /* @__PURE__ */ T({
    attributeMap: {},
    destinationAttribute: {},
    sourceAttributes: {},
    etlAttributeSetMapId: {}
  }, {
    modelValue: { default: () => [] },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(m) {
    const i = m, e = I(m, "modelValue"), { t: u } = L(), r = b([]), s = b(!1), y = N(
      () => {
        var t, n, a, l;
        return ((n = (t = i.sourceAttributes) == null ? void 0 : t[0]) == null ? void 0 : n.dataType) && j.includes((l = (a = i.sourceAttributes) == null ? void 0 : a[0]) == null ? void 0 : l.dataType);
      }
    );
    function M() {
      e.value.push({
        destinationValue: null,
        sourceValue: {
          value: null,
          friendlyName: null
        }
      });
    }
    function g({ rowIndex: t }) {
      e.value.length > 1 ? e.value.splice(t, 1) : e.value = [];
    }
    return E(
      () => {
        var t;
        return (t = i.sourceAttributes) == null ? void 0 : t[0];
      },
      async (t) => {
        var n, a;
        if (e.value = [], r.value = [], !!(t != null && t.id))
          try {
            s.value = !0;
            const { destinationTreeOptions: l, mapping: d } = await H.getMappingTableETLExtensionData({
              sourceAttributeId: t.id,
              destinationAttributeId: (n = i.destinationAttribute) == null ? void 0 : n.id,
              attributeMapId: (a = i.attributeMap) == null ? void 0 : a.id,
              etlAttributeSetMapId: i.etlAttributeSetMapId
            });
            e.value = (d == null ? void 0 : d.map(({ sourceValue: c, destinationValue: f }) => ({
              sourceValue: c,
              destinationValue: f ? Number(f) : null
            }))) ?? [], r.value = (l == null ? void 0 : l.map(
              ({ destinationValue: c }) => c
            )) ?? [];
          } finally {
            s.value = !1;
          }
      },
      { immediate: !0 }
    ), S(() => {
      Array.isArray(e.value) || (e.value = []);
    }), (t, n) => (v(), x("div", q, [
      Array.isArray(e.value) ? (v(), U(o(w), B({
        key: 0,
        data: e.value,
        "create-actions": y.value,
        "is-loading": s.value
      }, o(Y), {
        onCreate: M,
        onRemove: g
      }), {
        "cell-source": p(({ rowIndex: a }) => [
          V(o(R), {
            modelValue: e.value[a].sourceValue.friendlyName,
            "onUpdate:modelValue": (l) => e.value[a].sourceValue.friendlyName = l,
            label: o(u)("datahub-plugin.etl.unit-to-tree-node.sourceValue"),
            "persistent-placeholder": ""
          }, null, 8, ["modelValue", "onUpdate:modelValue", "label"])
        ]),
        "cell-destination": p(({ rowIndex: a }) => [
          V(o(P), {
            modelValue: e.value[a].destinationValue,
            "onUpdate:modelValue": (l) => e.value[a].destinationValue = l,
            items: r.value,
            label: o(u)("datahub-plugin.etl.unit-to-tree-node.destinationValue"),
            "item-title": "friendlyName",
            "persistent-placeholder": ""
          }, null, 8, ["modelValue", "onUpdate:modelValue", "items", "label"])
        ]),
        "no-data-description": p(() => [
          C(D(o(u)("datahub-plugin.etl.unit-to-tree-node.SelectSourceAttribute")), 1)
        ]),
        _: 1
      }, 16, ["data", "create-actions", "is-loading"])) : k("", !0)
    ]));
  }
});
typeof _ == "function" && _(A);
const ee = /* @__PURE__ */ $(A, [["__scopeId", "data-v-881983a8"]]);
export {
  ee as default
};
