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