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