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