import { defineComponent as U, ref as y, computed as v, resolveComponent as p, openBlock as d, createBlock as _, withCtx as g, createElementVNode as b, normalizeClass as D, toDisplayString as F, createVNode as I, createElementBlock as $, Fragment as E, renderList as B, unref as k } from "vue";
import { g as m } from "./decimal-C219qGO5.js";
import { d as L } from "./dayjs.min-D5mIeZ1x.js";
import { e as Y } from "./export-Dgopr7wH.js";
import { u as h } from "./app-Bpb4394e.js";
async function z(o) {
  const r = `${(h().currentLocation.name || "").replace(
    / /g,
    "_"
  )}_${L().format("DD_MM_YYYY_HHmm")}.xlsx`;
  await Y(
    [
      {
        name: "stock",
        data: o,
        columns: [
          {
            name: "Code",
            selector: "code"
          },
          {
            name: "Name",
            selector: "name"
          },
          {
            name: "Balance",
            selector: (e) => {
              const a = c(e, e.unit);
              return a.type === "unit" ? m(e.balance, e.unit, null, !1) : m(e.balance, e.unit, a.measurement, !1);
            }
          },
          {
            name: "Unit",
            selector: (e) => {
              var s;
              const a = c(e, e.unit);
              return a.type === "unit" ? e.unit.abbrev : ((s = e.unit.measurements.find((i) => i.id === a.measurement)) == null ? void 0 : s.abbrev) || "";
            }
          }
        ]
      }
    ],
    r
  );
}
function c(o, u) {
  const r = localStorage.getItem(`uom:${o._id}`);
  return r ? r === u._id ? {
    type: "unit"
  } : u.measurements.find((e) => e.id === r) ? {
    type: "measurement",
    measurement: r
  } : {
    type: "unit"
  } : o.trackingMeasurement && u.measurements.find((e) => e.id === o.trackingMeasurement) ? {
    type: "measurement",
    measurement: o.trackingMeasurement
  } : {
    type: "unit"
  };
}
const N = { class: "fm-typo-en-body-md-400 flex-grow" }, A = /* @__PURE__ */ U({
  __name: "UnitDisplayControl",
  props: {
    unit: {},
    sku: {},
    amount: {},
    defaultTrackingMeasurement: {}
  },
  setup(o) {
    function u(t) {
      return `uom:${t._id}`;
    }
    function r(t) {
      const n = u(e.sku);
      t ? localStorage.setItem(n, t) : localStorage.setItem(n, e.unit._id), a.value = c(e.sku, e.unit);
    }
    const e = o, a = y(c(e.sku, e.unit)), s = v(() => {
      const { measurements: t } = e.unit;
      return [
        {
          label: `${m(e.amount, e.unit)}`,
          value: null
        },
        ...t.map(({ id: n }) => ({
          label: `${m(e.amount, e.unit, n)}`,
          value: n
        }))
      ];
    });
    function i({ value: t }) {
      return k(a).type === "unit" ? t === null : t === k(a).measurement;
    }
    const x = v(
      () => {
        var t;
        return ((t = s.value.find((n) => i(n))) == null ? void 0 : t.label) ?? "";
      }
    ), f = y(!1);
    return (t, n) => {
      const M = p("FmIcon"), C = p("FmMenuItem"), S = p("FmMenu");
      return d(), _(S, {
        "stop-click-propagation": "",
        onMenuChanged: n[0] || (n[0] = (l) => f.value = l)
      }, {
        "menu-button": g(() => [
          b("button", {
            type: "button",
            class: D([
              "w-full text-left flex items-center gap-8 cursor-pointer fm-corner-radius-sm px-8 py-4 border bg-white",
              f.value ? "border-fm-color-primary" : "border-fm-color-neutral-gray-100"
            ])
          }, [
            b("div", N, F(x.value), 1),
            I(M, {
              class: "text-fm-color-neutral-gray-400",
              name: "expand_more"
            })
          ], 2)
        ]),
        default: g(() => [
          (d(!0), $(E, null, B(s.value, (l) => (d(), _(C, {
            key: l.value ?? 0,
            label: l.label,
            "model-value": i(l),
            onClick: (O) => r(l.value)
          }, null, 8, ["label", "model-value", "onClick"]))), 128))
        ]),
        _: 1
      });
    };
  }
});
export {
  A as _,
  z as o
};
