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