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