import { defineStore as t } from "pinia";
import "vue";
import { o as a, k as r } from "./start-BYfL32Oe.mjs";
import "vue-i18n";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { d as o } from "./Dimensions-BifiFDT9.mjs";
import { l as g } from "./Languages-BTMb-mkM.mjs";
import { t as c } from "./TreeNodeValueController-C5jYAiH7.mjs";
const h = () => ({
  currencies: [],
  isCurrenciesLoading: !1,
  isCurrenciesFetching: void 0,
  dimensions: [],
  isDimensionsLoading: !1,
  isDimensionsFetching: void 0,
  languages: [],
  isLanguagesLoading: !1,
  isLanguagesFetching: void 0,
  treeNodes: {},
  isTreeNodesLoading: {}
}), D = t("DataHub-dataTypes", {
  state: h,
  actions: {
    async fetchDimensions() {
      if (!this.dimensions.length) {
        if (this.isDimensionsFetching)
          return this.isDimensionsFetching;
        try {
          this.isDimensionsLoading = !0, this.isDimensionsFetching = o.getList();
          const { data: i } = await this.isDimensionsFetching;
          this.dimensions = i, this.isDimensionsFetching = void 0;
        } catch (i) {
          console.log(i.message);
        } finally {
          this.isDimensionsLoading = !1;
        }
      }
    },
    async fetchCurrencies() {
      if (!this.currencies.length) {
        if (this.isCurrenciesFetching)
          return this.isCurrenciesFetching;
        try {
          this.isCurrenciesLoading = !0, this.isCurrenciesFetching = r.listCurrencies();
          const { data: i } = await this.isCurrenciesFetching;
          this.currencies = i, this.isCurrenciesFetching = void 0;
        } catch (i) {
          console.log(i.message);
        } finally {
          this.isCurrenciesLoading = !1;
        }
      }
    },
    async fetchLanguages() {
      if (!this.languages.length) {
        if (this.isLanguagesFetching)
          return this.isLanguagesFetching;
        try {
          this.isLanguagesLoading = !0, this.isLanguagesFetching = g.getList();
          const { data: i } = await this.isLanguagesFetching;
          this.languages = i, this.isLanguagesFetching = void 0;
        } catch (i) {
          console.log(i.message);
        } finally {
          this.isLanguagesLoading = !1;
        }
      }
    },
    getTreeNodeKey: ({
      attributeId: i,
      scopeId: s,
      languageId: e,
      entityId: n
    }) => `${i}-${s}-${e}-${n}`,
    async fetchTreeNodes(i, s) {
      var n;
      const e = this.getTreeNodeKey(i);
      try {
        return this.isTreeNodesLoading[e] = !0, this.treeNodes[e] || (this.treeNodes[e] = (n = s.configuration) != null && n.alternativeConfiguration ? a.post(
          s.configuration.alternativeConfiguration.url,
          {
            ...i,
            ...s.configuration.alternativeConfiguration.params
          }
        ) : c.getTree(i)), await this.treeNodes[e];
      } finally {
        this.isTreeNodesLoading[e] = !1;
      }
    }
  }
});
export {
  D as u
};
