import { defineComponent as B, computed as T, watch as G, nextTick as j, createBlock as v, openBlock as y, unref as e, createSlots as q, withCtx as i, createVNode as n, createCommentVNode as R, withModifiers as x, isRef as P, mergeModels as z, useModel as J, ref as K, onBeforeMount as Q, mergeProps as W } from "vue";
import { storeToRefs as U } from "pinia";
import { useRouter as X } from "vue-router";
import { aH as Y, b1 as Z, aj as ee, ak as ae, h as oe, i as I, c as O, e as te, I as M, ai as le, aa as ne, ah as ie } from "./start-CE9SawgU.js";
import { useI18n as se } from "vue-i18n";
import { L as H, D as ue } from "./header-Bn1EKnBE.js";
import { c as F, s as S, d as de, C as re, i as me } from "./topBarRoutes-CBd5qLxn.js";
import { _ as ce } from "./ActivableTitle.vue_vue_type_script_setup_true_lang-CyPsm-pN.js";
import { _ as pe } from "./KeyTextField.vue_vue_type_script_setup_true_lang-CeedcDGI.js";
import { _ as fe } from "./TreeView.vue_vue_type_style_index_0_scoped_0bd14ef7_lang-CZieIjgg.js";
import { _ as ge } from "./CreateEntityModal.vue_vue_type_script_setup_true_lang-BoW_S4lT.js";
const be = /* @__PURE__ */ B({
  __name: "EditBasicView",
  props: {
    id: {},
    readonly: { type: Boolean },
    disableCustomSelection: { type: Boolean },
    pluginName: {}
  },
  emits: ["close"],
  setup(_, { emit: p }) {
    const s = _, m = p, { t: u } = se(), c = F(s.pluginName), { selectedScope: t, isLoadingScope: d } = U(c), w = T(
      () => u("datahub-ui.dh-shared.editScope", {
        channel: t.value?.name ?? ""
      })
    ), f = T(
      () => !!(t.value?.readOnly || s.readonly)
    ), A = {
      key: {},
      active: {}
    }, r = `${s.pluginName}-channels`, { v$: b, markTouched: L, resetValidation: N } = Y(
      r,
      {
        form: t,
        rules: A,
        formId: `${s.pluginName}-scope-basic`,
        onSubmit: D
      }
    ), C = Z(r), { isValid: h, isSubmitting: $ } = U(C), { submit: k } = C;
    async function D() {
      try {
        const { data: a } = await S.save(t.value);
        return t.value = {
          ...t.value,
          ...a
        }, N(), !0;
      } catch {
        return !1;
      }
    }
    async function l() {
      try {
        d.value = !0, await S.delete([Number(s.id)]), m("close");
      } finally {
        d.value = !1;
      }
    }
    return G(
      () => Number(s.id),
      async (a) => {
        a && (await c.fetchScope(a), await j(), N());
      },
      { immediate: !0 }
    ), (a, o) => (y(), v(e(ee), { loading: e(d) }, q({
      "toolbar-title": i(() => [
        n(ce, {
          title: w.value,
          active: e(t)?.active
        }, null, 8, ["title", "active"])
      ]),
      default: i(() => [
        n(de, {
          controller: e(H).SCOPES,
          api: e(S).getListOfLanguagesScopesAndFields,
          "disable-custom-selection": a.disableCustomSelection,
          "plugin-name": a.pluginName
        }, {
          default: i(({ selected: g, loading: E }) => [
            e(t) ? (y(), v(e(ae), {
              key: 0,
              readonly: f.value,
              class: "h-100 overflow-auto",
              onSubmit: o[3] || (o[3] = x(() => {
              }, ["prevent"]))
            }, {
              default: i(() => [
                n(e(oe), { fluid: "" }, {
                  default: i(() => [
                    n(e(I), null, {
                      default: i(() => [
                        n(e(O), {
                          md: "6",
                          lg: "4"
                        }, {
                          default: i(() => [
                            n(e(I), null, {
                              default: i(() => [
                                n(e(O), null, {
                                  default: i(() => [
                                    n(e(te), {
                                      modelValue: e(b).active.$model,
                                      "onUpdate:modelValue": o[0] || (o[0] = (V) => e(b).active.$model = V),
                                      label: a.$t("datahub-ui.dh-table.isActive"),
                                      readonly: f.value,
                                      loading: E
                                    }, null, 8, ["modelValue", "label", "readonly", "loading"])
                                  ]),
                                  _: 2
                                }, 1024),
                                n(e(O), null, {
                                  default: i(() => [
                                    n(pe, {
                                      modelValue: e(b).key.$model,
                                      "onUpdate:modelValue": o[1] || (o[1] = (V) => e(b).key.$model = V),
                                      readonly: f.value,
                                      loading: e(d) || E
                                    }, null, 8, ["modelValue", "readonly", "loading"])
                                  ]),
                                  _: 2
                                }, 1024),
                                g?.attributes?.length ? (y(), v(fe, {
                                  key: 0,
                                  modelValue: e(t),
                                  "onUpdate:modelValue": o[2] || (o[2] = (V) => P(t) ? t.value = V : null),
                                  attributes: g?.attributes,
                                  readonly: f.value,
                                  scopes: g.scopes,
                                  languages: g.languages,
                                  selection: g?.custom,
                                  loading: E,
                                  onUpdated: e(L)
                                }, null, 8, ["modelValue", "attributes", "readonly", "scopes", "languages", "selection", "loading", "onUpdated"])) : R("", !0)
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024)
                      ]),
                      _: 2
                    }, 1024)
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 2
            }, 1032, ["readonly"])) : R("", !0)
          ]),
          _: 1
        }, 8, ["controller", "api", "disable-custom-selection", "plugin-name"])
      ]),
      _: 2
    }, [
      a.readonly ? void 0 : {
        name: "toolbar-actions",
        fn: i(() => [
          n(e(M), {
            variant: "outlined",
            color: "secondary",
            destructive: "",
            "prepend-icon": "lucide:trash",
            disabled: !e(t) || e(d) || e($),
            text: a.$t("common.delete"),
            onClick: l
          }, null, 8, ["disabled", "text"]),
          n(e(M), {
            color: "primary",
            text: a.$t("common.saveChanges"),
            disabled: !e(t) || !e(h) || e(d),
            loading: e($),
            onClick: e(k)
          }, null, 8, ["text", "disabled", "loading", "onClick"])
        ]),
        key: "0"
      }
    ]), 1032, ["loading"]));
  }
}), ve = /* @__PURE__ */ B({
  __name: "CreateChannel",
  props: /* @__PURE__ */ z({
    pluginName: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(_) {
    const p = J(_, "modelValue"), s = K({});
    return (m, u) => (y(), v(ge, {
      modelValue: p.value,
      "onUpdate:modelValue": u[0] || (u[0] = (c) => p.value = c),
      form: s.value,
      "onUpdate:form": u[1] || (u[1] = (c) => s.value = c),
      title: m.$t("datahub-ui.dh-shared.newScope"),
      controller: e(H).SCOPES,
      "plugin-name": m.pluginName
    }, null, 8, ["modelValue", "form", "title", "controller", "plugin-name"]));
  }
}), ke = /* @__PURE__ */ B({
  __name: "ChannelsView",
  props: {
    pluginName: {}
  },
  setup(_) {
    const p = _, s = X();
    let m;
    const u = F(p.pluginName), { scopes: c, isLoadingScopes: t } = U(u), { fetchScopes: d, fetchLanguagesAndScopes: w } = u, { table: f, isLoading: A, showChangeDialog: r, onAddRow: b, onDeleteRows: L } = le({
      addApi: S.create,
      deleteApi: S.delete
    }), N = T(() => ({
      ...re,
      createActions: p.pluginName === ue
    }));
    function C(l, a) {
      L(ie(a));
    }
    async function h(l) {
      await s.push({
        name: me.CHANNELS,
        params: { channelId: l }
      });
    }
    async function $(l, a) {
      const o = await b(l);
      o && (r.value = !1, a && o.data?.id && await h(o.data.id));
    }
    function k(l) {
      l || f.value?.reloadTable();
    }
    function D(l) {
      m = l, d(m);
    }
    return Q(() => {
      w(
        H.SCOPES,
        S.getListOfLanguagesScopesAndFields
      );
    }), (l, a) => (y(), v(e(ne), W({
      ref_key: "table",
      ref: f,
      data: e(c),
      "is-loading": e(t),
      "disable-actions": e(A)
    }, N.value, {
      onAction: C,
      onCreate: a[1] || (a[1] = (o) => r.value = !0),
      onRefresh: a[2] || (a[2] = (o) => e(d)(e(m))),
      onRecalculate: D,
      onDetail: k
    }), {
      modals: i(() => [
        e(r) ? (y(), v(ve, {
          key: 0,
          modelValue: e(r),
          "onUpdate:modelValue": a[0] || (a[0] = (o) => P(r) ? r.value = o : null),
          loading: e(A),
          "plugin-name": l.pluginName,
          onSave: $
        }, null, 8, ["modelValue", "loading", "plugin-name"])) : R("", !0)
      ]),
      details: i(({ rowId: o, close: g }) => [
        n(be, {
          id: o,
          "plugin-name": l.pluginName,
          onClose: g
        }, null, 8, ["id", "plugin-name", "onClose"])
      ]),
      _: 1
    }, 16, ["data", "is-loading", "disable-actions"]));
  }
});
export {
  ke as default
};
