import { defineComponent as w, inject as O, computed as M, watch as G, nextTick as j, createBlock as C, openBlock as h, unref as e, createSlots as q, withCtx as d, createVNode as l, mergeModels as z, useModel as F, ref as Q, onBeforeMount as W, mergeProps as x, createCommentVNode as J, isRef as K } from "vue";
import { useRouter as X } from "vue-router";
import { storeToRefs as L } from "pinia";
import { aO as Y, aP as Z, ac as ee, ae, E as k, aC as te, a as U, h as le, c as B, aa as oe, a3 as ie, a9 as ne } from "./start-BYfL32Oe.mjs";
import { useI18n as se } from "vue-i18n";
import { L as H } from "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { L as P } from "./localPluginIntercom-Q4ih1XJC.mjs";
import { d as ue, c as D, e as de, p as re, R as me } from "./topBarRoutes-0VuQ_i6D.mjs";
import { _ as pe } from "./ActivableTitle.vue_vue_type_script_setup_true_lang-DCKPhi3v.mjs";
import { _ as ce } from "./CreateEntityModal.vue_vue_type_script_setup_true_lang-DlKTJeUM.mjs";
import { A as be } from "./tables-CDjuyVFN.mjs";
const fe = /* @__PURE__ */ w({
  __name: "EditView",
  props: {
    id: {},
    pluginName: {}
  },
  emits: ["close"],
  setup(f, { emit: y }) {
    const r = f, c = y, { t: g } = se(), { navigationItem: v } = O(P), A = Y(
      ue(v.name, de)
    ), T = Z(), { isValid: o, isSubmitting: m } = L(T), { submit: a, resetValidation: _ } = T, t = D(r.pluginName), { selectedAttribute: V, isLoadingAttribute: b } = L(
      t
    ), { attributesApi: p } = t, E = M(
      () => V.value ? `${g("datahub-ui.dh-shared.attribute")}: ${V.value.name}` : ""
    );
    async function S() {
      try {
        b.value = !0, await p.delete([Number(r.id)]), c("close");
      } finally {
        b.value = !1;
      }
    }
    return G(
      () => r.id,
      async (n) => {
        n && (await t.fetchAttribute(n), await j(), _());
      },
      { immediate: !0 }
    ), (n, I) => {
      var $;
      return h(), C(e(ee), null, q({
        "toolbar-title": d(() => {
          var N;
          return [
            l(pe, {
              title: E.value,
              active: (N = e(V)) == null ? void 0 : N.active
            }, null, 8, ["title", "active"])
          ];
        }),
        default: d(() => [
          l(e(ae), {
            tabs: e(A),
            level: "1",
            "router-props": { id: Number(n.id) }
          }, null, 8, ["tabs", "router-props"])
        ]),
        _: 2
      }, [
        ($ = e(V)) != null && $.readOnly ? void 0 : {
          name: "toolbar-actions",
          fn: d(() => [
            l(e(k), {
              variant: "text",
              color: "alert",
              "prepend-icon": "delete",
              disabled: !n.id || e(b),
              text: n.$t("common.delete"),
              onClick: S
            }, null, 8, ["disabled", "text"]),
            l(e(k), {
              color: "primary",
              variant: "flat",
              disabled: !e(o) || e(b),
              loading: e(m),
              text: n.$t("common.saveChanges"),
              onClick: e(a)
            }, null, 8, ["disabled", "loading", "text", "onClick"])
          ]),
          key: "0"
        }
      ]), 1024);
    };
  }
}), ge = /* @__PURE__ */ w({
  __name: "CreateAttribute",
  props: /* @__PURE__ */ z({
    pluginName: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(f) {
    const y = f, r = F(f, "modelValue"), c = D(y.pluginName), { dataTypes: g, isLoadingDataTypes: v } = L(c), A = Q({
      dataType: "",
      multilanguage: !1,
      scopable: !1
    }), T = {
      dataType: te,
      multilanguage: {},
      scopable: {}
    };
    return (o, m) => (h(), C(ce, {
      modelValue: r.value,
      "onUpdate:modelValue": m[0] || (m[0] = (a) => r.value = a),
      form: A.value,
      "onUpdate:form": m[1] || (m[1] = (a) => A.value = a),
      title: o.$t("datahub-ui.dh-shared.newAttribute"),
      controller: e(H).ATTRIBUTES,
      rules: T,
      "plugin-name": o.pluginName
    }, {
      default: d(({ v: a, validations: _ }) => [
        l(e(U), null, {
          default: d(() => [
            l(e(le), {
              modelValue: a.dataType.$model,
              "onUpdate:modelValue": (t) => a.dataType.$model = t,
              label: o.$t("datahub-ui.dh-table.dataType"),
              loading: e(v),
              "error-messages": Array.from(_.dataTypeErrors),
              items: e(g),
              "item-title": "name",
              "item-value": "id",
              search: "",
              "page-size": ""
            }, null, 8, ["modelValue", "onUpdate:modelValue", "label", "loading", "error-messages", "items"])
          ]),
          _: 2
        }, 1024),
        l(e(U), { md: "6" }, {
          default: d(() => [
            l(e(B), {
              modelValue: a.scopable.$model,
              "onUpdate:modelValue": (t) => a.scopable.$model = t,
              label: o.$t("datahub-ui.dh-table.multiChannel")
            }, null, 8, ["modelValue", "onUpdate:modelValue", "label"])
          ]),
          _: 2
        }, 1024),
        l(e(U), { md: "6" }, {
          default: d(() => [
            l(e(B), {
              modelValue: a.multilanguage.$model,
              "onUpdate:modelValue": (t) => a.multilanguage.$model = t,
              label: o.$t("datahub-ui.dh-table.multiLanguage")
            }, null, 8, ["modelValue", "onUpdate:modelValue", "label"])
          ]),
          _: 2
        }, 1024)
      ]),
      _: 1
    }, 8, ["modelValue", "form", "title", "controller", "plugin-name"]));
  }
}), Ee = /* @__PURE__ */ w({
  __name: "AttributesView",
  props: {
    pluginName: {}
  },
  setup(f) {
    const y = f, r = X();
    let c;
    const g = D(y.pluginName), { isLoadingDataTypes: v, isLoadingAttributes: A, attributes: T } = L(
      g
    ), { fetchAttributes: o, fetchLanguagesAndScopes: m, attributesApi: a } = g, { navigationItem: _ } = O(P), t = M(
      () => re(_.name, me.ATTRIBUTES)
    ), { table: V, isLoading: b, showChangeDialog: p, onAddRow: E, onDeleteRows: S } = oe({
      addApi: a.create,
      deleteApi: a.delete
    });
    function n(s, i) {
      S(ne(i));
    }
    async function I(s) {
      await r.push({
        name: t.value,
        params: { attributeId: s }
      });
    }
    async function $(s, i) {
      var R;
      const u = await E(s);
      u && (p.value = !1, i && ((R = u.data) != null && R.id) && await I(u.data.id));
    }
    function N(s) {
      c = s, o(c);
    }
    return W(() => {
      m(
        H.ATTRIBUTES,
        a.getListOfLanguagesScopesAndFields
      );
    }), (s, i) => (h(), C(e(ie), x({
      ref_key: "table",
      ref: V,
      "is-loading": e(v) || e(A),
      data: e(T),
      "disable-actions": e(b),
      routable: t.value,
      "dynamic-columns-endpoint": e(a).getColumns
    }, e(be), {
      onAction: n,
      onCreate: i[1] || (i[1] = (u) => p.value = !0),
      onRefresh: i[2] || (i[2] = (u) => e(o)(e(c))),
      onRecalculate: N
    }), {
      modals: d(() => [
        e(p) ? (h(), C(ge, {
          key: 0,
          modelValue: e(p),
          "onUpdate:modelValue": i[0] || (i[0] = (u) => K(p) ? p.value = u : null),
          loading: e(b),
          "plugin-name": s.pluginName,
          onSave: $
        }, null, 8, ["modelValue", "loading", "plugin-name"])) : J("", !0)
      ]),
      details: d(({ rowId: u, close: R }) => [
        l(fe, {
          id: u,
          "plugin-name": s.pluginName,
          onClose: R
        }, null, 8, ["id", "plugin-name", "onClose"])
      ]),
      _: 1
    }, 16, ["is-loading", "data", "disable-actions", "routable", "dynamic-columns-endpoint"]));
  }
});
export {
  Ee as default
};
