import { defineComponent as y, inject as D, computed as L, watch as P, nextTick as H, createBlock as T, openBlock as _, unref as e, createSlots as x, withCtx as f, createVNode as A, mergeModels as G, useModel as j, ref as q, onBeforeMount as F, mergeProps as W, createCommentVNode as z, isRef as J } from "vue";
import { useRouter as K } from "vue-router";
import { storeToRefs as w } from "pinia";
import { aO as Q, aP as X, ac as Y, ae as Z, E as ee, aa as te, a3 as ae, a9 as oe } from "./start-BYfL32Oe.mjs";
import { useI18n as ie } from "vue-i18n";
import { L as I } from "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { L as $ } from "./localPluginIntercom-Q4ih1XJC.mjs";
import { d as ne, i as se, c as h, p as le, R as re } from "./topBarRoutes-0VuQ_i6D.mjs";
import { _ as ue } from "./ActivableTitle.vue_vue_type_script_setup_true_lang-DCKPhi3v.mjs";
import { _ as me } from "./CreateEntityModal.vue_vue_type_script_setup_true_lang-DlKTJeUM.mjs";
import { A as de } from "./tables-C7wXlu25.mjs";
const pe = /* @__PURE__ */ y({
  __name: "EditView",
  props: {
    id: {},
    pluginName: {}
  },
  emits: ["close"],
  setup(c) {
    const r = c, { t: m } = ie(), { navigationItem: s } = D($), a = Q(
      ne(s.name, se)
    ), l = X(), { isValid: N, isSubmitting: R } = w(l), { submit: b, resetValidation: V } = l, d = h(r.pluginName), { selectedAttributeSet: p, isLoadingAttributeSet: g } = w(
      d
    ), C = L(
      () => p.value ? `${m("datahub-ui.dh-shared.attributeSet")}: ${p.value.name}` : ""
    );
    return P(
      () => r.id,
      async (u) => {
        u && (await d.fetchAttributeSet(u), await H(), V());
      },
      { immediate: !0 }
    ), (u, E) => {
      var o;
      return _(), T(e(Y), null, x({
        "toolbar-title": f(() => {
          var S;
          return [
            A(ue, {
              title: C.value,
              active: (S = e(p)) == null ? void 0 : S.active
            }, null, 8, ["title", "active"])
          ];
        }),
        default: f(() => [
          A(e(Z), {
            tabs: e(a),
            level: "1",
            "router-props": { id: Number(u.id) }
          }, null, 8, ["tabs", "router-props"])
        ]),
        _: 2
      }, [
        (o = e(p)) != null && o.readOnly ? void 0 : {
          name: "toolbar-actions",
          fn: f(() => [
            A(e(ee), {
              color: "primary",
              variant: "flat",
              disabled: !e(N) || e(g),
              loading: e(R),
              text: u.$t("common.saveChanges"),
              onClick: e(b)
            }, null, 8, ["disabled", "loading", "text", "onClick"])
          ]),
          key: "0"
        }
      ]), 1024);
    };
  }
}), ce = /* @__PURE__ */ y({
  __name: "CreateAttributeSet",
  props: /* @__PURE__ */ G({
    pluginName: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(c) {
    const r = j(c, "modelValue"), m = q({});
    return (s, a) => (_(), T(me, {
      modelValue: r.value,
      "onUpdate:modelValue": a[0] || (a[0] = (l) => r.value = l),
      form: m.value,
      "onUpdate:form": a[1] || (a[1] = (l) => m.value = l),
      title: s.$t("datahub-ui.dh-shared.newAttributeSet"),
      controller: e(I).ATTRIBUTE_SETS,
      "plugin-name": s.pluginName
    }, null, 8, ["modelValue", "form", "title", "controller", "plugin-name"]));
  }
}), Ee = /* @__PURE__ */ y({
  __name: "AttributeSetsView",
  props: {
    pluginName: {}
  },
  setup(c) {
    const r = c, m = K();
    let s;
    const a = h(r.pluginName), { attributeSets: l, isLoadingAttributeSets: N, allowedCreateAttributeSet: R } = w(a), { fetchAttributeSets: b, fetchLanguagesAndScopes: V, attributeSetsApi: d } = a, { navigationItem: p } = D($), g = L(
      () => le(p.name, re.ATTRIBUTE_SETS)
    ), C = L(() => ({
      ...de,
      dynamicColumnsEndpoint: d.getColumns,
      routable: g.value,
      createActions: R.value,
      data: l.value,
      isLoading: N.value
    })), { table: u, isLoading: E, showChangeDialog: o, onAddRow: S, onDeleteRows: B } = te({
      addApi: d.create
      // deleteApi: attributeSetsApi.delete, // @todo TASK-78 BE return error method not found
    });
    function O(i, t) {
      B(oe(t));
    }
    async function U(i) {
      await m.push({
        name: g.value,
        params: { attributeSetId: i }
      });
    }
    async function k(i, t) {
      var v;
      const n = await S(i);
      n && (o.value = !1, t && ((v = n.data) != null && v.id) && await U(n.data.id));
    }
    function M(i) {
      s = i, b(!0, s);
    }
    return F(() => {
      V(
        I.ATTRIBUTE_SETS,
        d.getListOfLanguagesScopesAndFields
      );
    }), (i, t) => (_(), T(e(ae), W({
      ref_key: "table",
      ref: u,
      "disable-actions": e(E)
    }, C.value, {
      onAction: O,
      onCreate: t[1] || (t[1] = (n) => o.value = !0),
      onRefresh: t[2] || (t[2] = (n) => e(b)(!0, e(s))),
      onRecalculate: M
    }), {
      modals: f(() => [
        e(o) ? (_(), T(ce, {
          key: 0,
          modelValue: e(o),
          "onUpdate:modelValue": t[0] || (t[0] = (n) => J(o) ? o.value = n : null),
          loading: e(E),
          "plugin-name": i.pluginName,
          onSave: k
        }, null, 8, ["modelValue", "loading", "plugin-name"])) : z("", !0)
      ]),
      details: f(({ rowId: n, close: v }) => [
        A(pe, {
          id: n,
          "plugin-name": i.pluginName,
          onClose: v
        }, null, 8, ["id", "plugin-name", "onClose"])
      ]),
      _: 1
    }, 16, ["disable-actions"]));
  }
});
export {
  Ee as default
};
