import { computed as r, defineComponent as p, ref as h, watch as V, createBlock as I, openBlock as T, unref as o, withCtx as m, createVNode as b, mergeProps as _, createElementVNode as L, createTextVNode as O, toDisplayString as v } from "vue";
import { af as s, a1 as E, a2 as A, aj as B, aa as N, ah as W } from "./start-CE9SawgU.js";
import { useI18n as w } from "vue-i18n";
import "pinia";
import "./header-Bn1EKnBE.js";
import { d as S } from "./dataTypes-DocW2t0g.js";
import { i as U, I as G, T as d } from "./topBarRoutes-CBd5qLxn.js";
import { u as M } from "./Units-B45W1CXa.js";
import { _ as P } from "./ActivableTitle.vue_vue_type_script_setup_true_lang-CyPsm-pN.js";
const x = {
  data: S.getList,
  gridId: "datahub-dimensions",
  rowSelection: A.NONE,
  hideGlobalSearch: !1,
  hideFilters: !1,
  hideColumnCustomization: !1,
  hidePagination: !1,
  sortType: E.SINGLE,
  routableId: "dimensionId",
  routable: U.DIMENSIONS,
  createActions: !1,
  reloadOnLocaleChange: !0,
  columns: [
    {
      id: "id",
      header: "common.id",
      isVisible: !1,
      minWidth: 200,
      filterable: s.NUMERIC,
      sortable: !0
    },
    {
      id: "name",
      header: "datahub-ui.dh-table.name",
      minWidth: 200,
      filterable: !1,
      sortable: !0
    },
    {
      id: "units",
      header: "datahub-ui.dimensions.units",
      minWidth: 200,
      filterable: !1,
      sortable: !1,
      accessor: ({ baseUnit: e, units: a }) => {
        const u = e.symbol ?? "", i = a.map(({ id: t, symbol: l }) => t !== e.id && l).filter(Boolean).join(", ");
        return { base: u, units: i };
      }
    }
  ]
}, R = {
  // data: dimensionsApi.getList,
  gridId: "datahub-dimension-units",
  rowSelection: A.MULTI,
  hideGlobalSearch: !1,
  hideFilters: !1,
  hideColumnCustomization: !1,
  hidePagination: !1,
  sortType: E.SINGLE,
  createActions: !1,
  tableActions: [
    {
      title: "datahub-ui.dimensions.activate",
      color: "primary",
      variant: "flat",
      event: d.ACTIVATE,
      prepareIsDisabled: ({ selectedRows: e }) => r(() => !e.value.length || e.value.every(({ active: a }) => a)),
      prepareIsHidden: ({ selectedRows: e }) => r(
        () => !!(e.value.length && e.value.every(({ active: a }) => a))
      )
    },
    {
      title: "datahub-ui.dimensions.deactivate",
      variant: "outlined",
      color: "secondary",
      destructive: !0,
      event: d.DEACTIVATE,
      prepareIsDisabled: ({ selectedRows: e }) => r(
        () => !e.value.length || e.value.every(({ active: a }) => !a)
      ),
      prepareIsHidden: ({ selectedRows: e }) => r(
        () => !e.value.length || e.value.some(({ active: a }) => !a)
      )
    }
  ],
  columns: [
    {
      id: "id",
      header: "common.id",
      isVisible: !1,
      minWidth: 200,
      filterable: s.NUMERIC,
      sortable: !0
    },
    {
      id: "active",
      header: "datahub-ui.dh-table.status",
      renderer: "IsActiveStatusCell",
      minWidth: 100,
      width: 150,
      ...G,
      sortable: !0
    },
    {
      id: "name",
      header: "datahub-ui.dh-table.name",
      minWidth: 200,
      filterable: s.STRING,
      sortable: !0
    },
    {
      id: "symbol",
      header: "datahub-ui.dimensions.symbol",
      minWidth: 200,
      filterable: s.STRING,
      sortable: !0
    },
    {
      id: "factor",
      header: "datahub-ui.dimensions.factor",
      minWidth: 200,
      filterable: s.STRING,
      sortable: !0
    },
    {
      id: "isBaseUnit",
      header: "datahub-ui.dimensions.baseUnit",
      renderer: "CheckboxCell",
      minWidth: 200,
      filterable: s.BOOLEAN,
      sortable: !0
    }
  ]
}, k = /* @__PURE__ */ p({
  __name: "EditBasicView",
  props: {
    id: {}
  },
  setup(e) {
    const a = e, { t: u } = w(), i = h({ units: [] }), t = h(!1), l = h(!1), g = r(
      () => u("datahub-ui.dimensions.editDimension", {
        dimension: i.value?.name ?? ""
      })
    );
    async function f(n) {
      if (i.value = { units: [] }, !!n)
        try {
          t.value = !0;
          const { data: c } = await S.getOne(n);
          i.value = c;
        } finally {
          t.value = !1;
        }
    }
    async function C(n, c) {
      const y = n === d.ACTIVATE, D = W(c);
      switch (n) {
        case d.ACTIVATE:
        case d.DEACTIVATE:
          try {
            l.value = !0, await M.activateDeactivateUnits(D, y), await f(Number(a.id));
          } finally {
            l.value = !1;
          }
          return;
      }
    }
    return V(() => Number(a.id), f, { immediate: !0 }), (n, c) => (T(), I(o(B), { loading: t.value }, {
      "toolbar-title": m(() => [
        b(P, {
          title: g.value,
          active: i.value?.active
        }, null, 8, ["title", "active"])
      ]),
      default: m(() => [
        b(o(N), _({
          embedded: "",
          "is-loading": t.value,
          data: i.value.units,
          "disable-actions": l.value
        }, o(R), { onAction: C }), null, 16, ["is-loading", "data", "disable-actions"])
      ]),
      _: 1
    }, 8, ["loading"]));
  }
}), Q = /* @__PURE__ */ p({
  __name: "DimensionsView",
  setup(e) {
    return (a, u) => (T(), I(o(N), _({ ref: "table" }, o(x)), {
      "cell-units": m(({ cellValue: { base: i, units: t } }) => [
        L("b", null, v(i) + ", ", 1),
        O(" " + v(t), 1)
      ]),
      details: m(({ rowId: i }) => [
        b(k, {
          id: i
        }, null, 8, ["id"])
      ]),
      _: 1
    }, 16));
  }
});
export {
  Q as default
};
