import { defineComponent as N, mergeModels as E, useModel as R, computed as $, createBlock as A, openBlock as S, unref as e, withCtx as s, createCommentVNode as P, withModifiers as G, createVNode as o, ref as k, watch as W, mergeProps as D, createElementVNode as j, isRef as C } from "vue";
import { storeToRefs as x } from "pinia";
import { X as B, ak as z, h as Q, i as X, c as I, d as J, e as w, j as K, k as Y, I as Z, a2 as ee, ai as te, aa as ae } from "./start-CE9SawgU.js";
import { useI18n as le } from "vue-i18n";
import "./header-Bn1EKnBE.js";
import { c as U } from "./topBarRoutes-CBd5qLxn.js";
import { A as ie, a as ue } from "./tables-Cd_ng5pg.js";
const oe = /* @__PURE__ */ N({
  __name: "AssignedSetDetails",
  props: /* @__PURE__ */ E({
    attributeSet: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(c) {
    const m = c, d = R(c, "modelValue"), { t: f } = le(), h = $(
      () => `${f("datahub-ui.dh-shared.attributeSets:")} ${m.attributeSet?.attributeSetName ?? ""}`
    );
    return (i, t) => (S(), A(e(B), {
      modelValue: d.value,
      "onUpdate:modelValue": t[1] || (t[1] = (g) => d.value = g),
      title: h.value,
      "min-width": "600px",
      "max-width": "800px"
    }, {
      default: s(() => [
        i.attributeSet ? (S(), A(e(z), {
          key: 0,
          onSubmit: t[0] || (t[0] = G(() => {
          }, ["prevent"]))
        }, {
          default: s(() => [
            o(e(Q), {
              class: "pa-0 mt-1",
              fluid: ""
            }, {
              default: s(() => [
                o(e(X), null, {
                  default: s(() => [
                    o(e(I), null, {
                      default: s(() => [
                        o(e(J), {
                          "model-value": i.attributeSet.attributeSetName,
                          label: i.$t("datahub-ui.dh-table.name"),
                          readonly: ""
                        }, null, 8, ["model-value", "label"])
                      ]),
                      _: 1
                    }),
                    o(e(I), null, {
                      default: s(() => [
                        o(e(w), {
                          "model-value": i.attributeSet.requireFlag,
                          label: i.$t("datahub-ui.dh-table.requiredFlag"),
                          readonly: ""
                        }, null, 8, ["model-value", "label"]),
                        o(e(w), {
                          "model-value": i.attributeSet.inherited,
                          label: i.$t("datahub-ui.dh-table.inherited"),
                          readonly: ""
                        }, null, 8, ["model-value", "label"]),
                        o(e(w), {
                          "model-value": i.attributeSet.calculatedFromFields,
                          label: i.$t("datahub-ui.dh-table.calculatedFromFields"),
                          readonly: ""
                        }, null, 8, ["model-value", "label"])
                      ]),
                      _: 1
                    })
                  ]),
                  _: 1
                })
              ]),
              _: 1
            })
          ]),
          _: 1
        })) : P("", !0)
      ]),
      _: 1
    }, 8, ["modelValue", "title"]));
  }
}), se = { class: "w-100" }, ne = /* @__PURE__ */ N({
  __name: "AddAssignedSets",
  props: /* @__PURE__ */ E({
    pluginName: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: /* @__PURE__ */ E(["save"], ["update:modelValue"]),
  setup(c) {
    const m = c, d = R(c, "modelValue"), f = U(m.pluginName), { attributeSetsApi: h } = f, i = $(() => ({
      filter: [
        { value: !1, operator: "=", active: !0, property: "readOnly" }
      ]
    })), t = k([]), g = $(
      () => t.value.length > 0 && t.value.every(({ attributeSetId: a }) => a)
    );
    function V() {
      t.value.push({});
    }
    function y(a, b) {
      t.value = t.value.map(
        (u, l) => l === b ? { ...u, ...a } : u
      );
    }
    function T({ rowIndex: a }) {
      t.value.splice(a, 1);
    }
    return W(d, (a) => {
      a && (t.value = []);
    }), (a, b) => (S(), A(e(B), {
      modelValue: d.value,
      "onUpdate:modelValue": b[1] || (b[1] = (u) => d.value = u),
      title: a.$t("datahub-ui.dh-shared.newAttributeSetAssignment"),
      "min-width": "600px",
      "max-width": "800px"
    }, {
      actions: s(() => [
        o(e(Z), {
          disabled: !g.value,
          text: a.$t("datahub-ui.dh-shared.applyAttributeSetAssignments"),
          color: "primary",
          onClick: b[0] || (b[0] = (u) => a.$emit("save", t.value))
        }, null, 8, ["disabled", "text"])
      ]),
      default: s(() => [
        o(e(K), D({
          data: t.value,
          "create-actions": [
            {
              title: a.$t("datahub-ui.dh-shared.newAttributeSet"),
              icon: "lucide:plus"
            }
          ]
        }, e(ie), {
          onCreate: V,
          onRemove: T
        }), {
          "cell-attributeSetId": s(({ rowIndex: u, row: l }) => [
            j("div", se, [
              o(e(Y), {
                data: e(h).getList,
                text: l?.name || "",
                "custom-query": i.value,
                "item-title": "name",
                "item-value": "id",
                "page-size": "",
                "prepend-text": "",
                block: "",
                select: "",
                search: "",
                onChange: (v) => y(
                  {
                    name: v?.name,
                    id: v?.id,
                    attributeSetId: v?.id
                  },
                  u
                )
              }, null, 8, ["data", "text", "custom-query", "onChange"])
            ])
          ]),
          "cell-requireFlag": s(({ rowIndex: u, cellValue: l }) => [
            o(e(w), {
              "model-value": l,
              label: a.$t("datahub-ui.dh-shared.required"),
              "onUpdate:modelValue": (v) => y({ requireFlag: v }, u)
            }, null, 8, ["model-value", "label", "onUpdate:modelValue"])
          ]),
          _: 1
        }, 16, ["data", "create-actions"])
      ]),
      _: 1
    }, 8, ["modelValue", "title"]));
  }
}), fe = /* @__PURE__ */ N({
  __name: "EditAssignedView",
  props: {
    id: {},
    pluginName: {}
  },
  setup(c) {
    const m = c, d = k(), f = U(m.pluginName), {
      selectedAttribute: h,
      selectedAttributeAssignments: i,
      isLoadingAttributeAssignments: t
    } = x(f), { fetchAttributeAssignments: g, attributeSetsApi: V } = f, y = $(() => {
      const r = h.value?.readOnly ? {
        createActions: !1,
        tableActions: void 0,
        rowSelection: ee.NONE
      } : void 0;
      return {
        ...ue,
        ...r,
        data: i.value,
        isLoading: !m.id || t.value
      };
    }), {
      table: T,
      showError: a,
      isLoading: b,
      isEditMode: u,
      showChangeDialog: l,
      onAddRow: v,
      onDeleteRows: F,
      batchApiCalls: _
    } = te({
      addApi: V.addAttributes,
      deleteApi: V.removeAttribute
    });
    function L(r) {
      d.value = r, u.value = !0, l.value = !0;
    }
    function q() {
      u.value = !1, l.value = !0;
    }
    function M(r, n) {
      _(
        F,
        n.map(({ attributeSetId: p }) => [p, m.id]),
        !1
      );
    }
    async function O(r) {
      const n = r.map(({ attributeSetId: p, requireFlag: H }) => [
        {
          dhAttributeSetId: p,
          dhAttributeIds: [m.id],
          requireFlag: H
        }
      ]);
      await _(v, n, !1), a.value || (l.value = !1);
    }
    return (r, n) => (S(), A(e(ae), D({
      ref_key: "table",
      ref: T,
      "disable-actions": e(b),
      embedded: ""
    }, y.value, {
      onCreate: q,
      onClickedRow: L,
      onAction: M,
      onRefresh: n[2] || (n[2] = (p) => e(g)(r.id))
    }), {
      modals: s(() => [
        e(u) ? (S(), A(oe, {
          key: 0,
          modelValue: e(l),
          "onUpdate:modelValue": n[0] || (n[0] = (p) => C(l) ? l.value = p : null),
          "attribute-set": d.value
        }, null, 8, ["modelValue", "attribute-set"])) : (S(), A(ne, {
          key: 1,
          modelValue: e(l),
          "onUpdate:modelValue": n[1] || (n[1] = (p) => C(l) ? l.value = p : null),
          "plugin-name": r.pluginName,
          onSave: O
        }, null, 8, ["modelValue", "plugin-name"]))
      ]),
      _: 1
    }, 16, ["disable-actions"]));
  }
});
export {
  fe as default
};
