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