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