import { computed as d, defineComponent as I, ref as c, watch as B, createBlock as T, openBlock as A, unref as r, withCtx as b, createVNode as f, mergeProps as E, createElementVNode as D, createTextVNode as g, toDisplayString as v } from "vue";
import { a7 as t, V as _, W as y, ac as L, a3 as V, a9 as O } from "./start-BYfL32Oe.mjs";
import { useI18n as w } from "vue-i18n";
import "pinia";
import "vue-router";
import "./header-Droxy2Kd.mjs";
import "./moment-h96o7c8I.mjs";
import { d as C } from "./Dimensions-BifiFDT9.mjs";
import { I as S, T as n } from "./topBarRoutes-0VuQ_i6D.mjs";
import { u as G } from "./Units-Df0X0ye0.mjs";
import { _ as M } from "./ActivableTitle.vue_vue_type_script_setup_true_lang-DCKPhi3v.mjs";
const P = {
  data: C.getList,
  gridId: "datahub-dimensions",
  rowSelection: y.MULTI,
  hideGlobalSearch: !1,
  hideFilters: !1,
  hideColumnCustomization: !1,
  hidePagination: !1,
  sortType: _.SINGLE,
  routableId: "dimensionId",
  createActions: !1,
  columns: [
    {
      id: "id",
      header: "common.id",
      isVisible: !1,
      minWidth: 200,
      filterable: t.NUMERIC,
      sortable: !0
    },
    {
      id: "active",
      header: "datahub-ui.dh-table.status",
      renderer: "IsActiveStatusCell",
      minWidth: 100,
      width: 150,
      ...S,
      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: (e) => {
        const a = e.baseUnit.symbol ?? "", o = e.units.map(({ id: i, symbol: l }) => i !== e.baseUnit.id && l).filter(Boolean).join(", ");
        return { base: a, units: o };
      }
    },
    {
      id: "created",
      header: "datahub-ui.dh-table.created",
      minWidth: 200,
      filterable: t.DATE,
      sortable: !0
    },
    {
      id: "createdByUsername",
      header: "datahub-ui.dh-table.createdByUsername",
      minWidth: 200,
      isVisible: !1,
      filterable: !1,
      sortable: !1
    },
    {
      id: "modified",
      header: "datahub-ui.dh-table.modified",
      minWidth: 200,
      isVisible: !1,
      filterable: t.DATE,
      sortable: !0
    },
    {
      id: "modifiedByUsername",
      header: "datahub-ui.dh-table.modifiedByUsername",
      minWidth: 200,
      isVisible: !1,
      filterable: !1,
      sortable: !1
    }
  ]
}, x = {
  // data: dimensionsApi.getList,
  gridId: "datahub-dimension-units",
  rowSelection: y.MULTI,
  hideGlobalSearch: !1,
  hideFilters: !1,
  hideColumnCustomization: !1,
  hidePagination: !1,
  sortType: _.SINGLE,
  createActions: !1,
  tableActions: [
    {
      title: "datahub-ui.dimensions.activate",
      variant: "elevated",
      color: "primary",
      event: n.ACTIVATE,
      prepareIsDisabled: ({ selectedRows: e }) => d(() => !e.value.length || e.value.every(({ active: a }) => a)),
      prepareIsHidden: ({ selectedRows: e }) => d(
        () => !!(e.value.length && e.value.every(({ active: a }) => a))
      )
    },
    {
      title: "datahub-ui.dimensions.deactivate",
      variant: "elevated",
      color: "primary",
      event: n.DEACTIVATE,
      prepareIsDisabled: ({ selectedRows: e }) => d(
        () => !e.value.length || e.value.every(({ active: a }) => !a)
      ),
      prepareIsHidden: ({ selectedRows: e }) => d(
        () => !e.value.length || e.value.some(({ active: a }) => !a)
      )
    }
  ],
  columns: [
    {
      id: "id",
      header: "common.id",
      isVisible: !1,
      minWidth: 200,
      filterable: t.NUMERIC,
      sortable: !0
    },
    {
      id: "active",
      header: "datahub-ui.dh-table.status",
      renderer: "IsActiveStatusCell",
      minWidth: 100,
      width: 150,
      ...S,
      sortable: !0
    },
    {
      id: "name",
      header: "datahub-ui.dh-table.name",
      minWidth: 200,
      filterable: t.STRING,
      sortable: !0
    },
    {
      id: "symbol",
      header: "datahub-ui.dimensions.symbol",
      minWidth: 200,
      filterable: t.STRING,
      sortable: !0
    },
    {
      id: "factor",
      header: "datahub-ui.dimensions.factor",
      minWidth: 200,
      filterable: t.STRING,
      sortable: !0
    },
    {
      id: "isBaseUnit",
      header: "datahub-ui.dimensions.baseUnit",
      renderer: "CheckboxCell",
      minWidth: 200,
      filterable: t.BOOLEAN,
      sortable: !0
    },
    {
      id: "dimensionId",
      header: "datahub-ui.dimensions.dimensionId",
      minWidth: 200,
      filterable: t.NUMERIC,
      sortable: !0
    },
    {
      id: "created",
      header: "datahub-ui.dh-table.created",
      minWidth: 200,
      filterable: t.DATE,
      sortable: !0
    },
    {
      id: "createdByUsername",
      header: "datahub-ui.dh-table.createdByUsername",
      minWidth: 200,
      isVisible: !1,
      filterable: !1,
      sortable: !1
    },
    {
      id: "modified",
      header: "datahub-ui.dh-table.modified",
      minWidth: 200,
      isVisible: !1,
      filterable: t.DATE,
      sortable: !0
    },
    {
      id: "modifiedByUsername",
      header: "datahub-ui.dh-table.modifiedByUsername",
      minWidth: 200,
      isVisible: !1,
      filterable: !1,
      sortable: !1
    }
  ]
}, R = /* @__PURE__ */ I({
  __name: "EditBasicView",
  props: {
    id: {}
  },
  setup(e) {
    const a = e, { t: o } = w(), i = c({ units: [] }), l = c(!1), h = c(!1), W = d(
      () => {
        var s;
        return o("datahub-ui.dimensions.editDimension", {
          dimension: ((s = i.value) == null ? void 0 : s.name) ?? ""
        });
      }
    );
    async function p(s) {
      if (i.value = { units: [] }, !!s)
        try {
          l.value = !0;
          const { data: u } = await C.getOne(s);
          i.value = u;
        } finally {
          l.value = !1;
        }
    }
    async function N(s, u) {
      const m = s === n.ACTIVATE, U = O(u);
      switch (s) {
        case n.ACTIVATE:
        case n.DEACTIVATE:
          try {
            h.value = !0, await G.activateDeactivateUnits(U, m), await p(Number(a.id));
          } finally {
            h.value = !1;
          }
          return;
      }
    }
    return B(() => Number(a.id), p, { immediate: !0 }), (s, u) => (A(), T(r(L), null, {
      "toolbar-title": b(() => {
        var m;
        return [
          f(M, {
            title: W.value,
            active: (m = i.value) == null ? void 0 : m.active
          }, null, 8, ["title", "active"])
        ];
      }),
      default: b(() => [
        f(r(V), E({
          "is-loading": l.value,
          data: i.value.units,
          "disable-actions": h.value
        }, r(x), { onAction: N }), null, 16, ["is-loading", "data", "disable-actions"])
      ]),
      _: 1
    }));
  }
}), X = /* @__PURE__ */ I({
  __name: "DimensionsView",
  setup(e) {
    return (a, o) => (A(), T(r(V), E({ ref: "table" }, r(P)), {
      "cell-units": b(({ cellValue: { base: i, units: l } }) => [
        D("b", null, v(i) + ", ", 1),
        g(" " + v(l), 1)
      ]),
      details: b(({ rowId: i }) => [
        f(R, {
          id: i
        }, null, 8, ["id"])
      ]),
      _: 1
    }, 16));
  }
});
export {
  X as default
};
