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