import { computed as T } from "vue";
import { am as P, R as e, b, an as A, a2 as O } from "./app-Bpb4394e.js";
import { useCoreStore as C, useI18n as L } from "@feedmepos/mf-common";
import { u as _ } from "./feature-Cz6F0_cm.js";
const G = P.reduce(
  (o, i) => {
    var s;
    return i.name && (o[i.name] = (s = i.meta) == null ? void 0 : s.validationManifest), o;
  },
  {}
);
function p() {
  const o = C(), i = _(), { t: s } = L(), { isDev: c } = b(), l = (r) => A(r, s), N = T(
    () => {
      var r;
      return ((r = o.sessionUser.value) == null ? void 0 : r.permissions) ?? [];
    }
  ), h = (r = []) => r.length === 0 ? !0 : O(r, N.value).granted, a = (r) => {
    const n = G[r];
    return h(n == null ? void 0 : n.requiredCaslPermissions);
  }, R = (r) => r.filter((n) => !n.hide).map((n) => n.children ? { ...n, children: R(n.children) } : n).filter((n) => !n.children || n.children.length > 0), I = (r) => r.map((n) => {
    const { hide: E, children: t, ...u } = n, S = { ...u };
    return t && (S.children = I(t)), S;
  }), d = T(() => {
    var E;
    const r = [
      {
        label: "Non-Production Environment",
        icon: "logo_dev",
        disabled: !0,
        hide: !c
      },
      {
        label: l(e.STOCK),
        children: [
          {
            label: s("inventory.stock.stock_balance.title"),
            value: e.STOCK,
            hide: !a(e.STOCK)
          },
          {
            label: l(e.UNIT_COST_HISTORY),
            value: e.UNIT_COST_HISTORY,
            hide: !a(e.UNIT_COST_HISTORY) || !i.enableTotalCost
          },
          {
            label: l(e.WASTAGE_TEMPLATE),
            value: e.WASTAGE_TEMPLATE,
            hide: !a(e.WASTAGE_TEMPLATE) || !i.enableWastageTemplate
          }
        ]
      },
      {
        label: s("inventory.closing.title"),
        children: [
          {
            label: l(e.CLOSING_HISTORY),
            value: e.CLOSING_HISTORY,
            hide: !a(e.CLOSING_HISTORY)
          },
          {
            label: l(e.CLOSING_TEMPLATE),
            value: e.CLOSING_TEMPLATE,
            hide: !a(e.CLOSING_TEMPLATE) || !i.enableClosingTemplate
          },
          {
            label: l(e.CLOSING_DRAFT),
            value: e.CLOSING_DRAFT,
            hide: !a(e.CLOSING_DRAFT) || !i.enableClosingTemplate
          }
        ]
      },
      {
        label: l(e.INGREDIENTS),
        value: e.INGREDIENTS,
        hide: !a(e.INGREDIENTS)
      },
      {
        label: l(e.INGREDIENT_GROUP),
        value: e.INGREDIENT_GROUP,
        hide: !a(e.INGREDIENT_GROUP) || !i.enableIngredientGroup
      },
      {
        label: l(e.RECIPE),
        value: e.RECIPE,
        hide: !a(e.RECIPE)
      },
      {
        label: l(e.UNIT),
        value: e.UNIT,
        hide: !a(e.UNIT)
      },
      {
        label: s("inventory.transfer.title"),
        children: [
          {
            label: l(e.RECEIVE_REQUEST),
            value: e.RECEIVE_REQUEST,
            hide: !a(e.RECEIVE_REQUEST)
          },
          {
            label: l(e.APPROVAL),
            value: e.APPROVAL,
            hide: !a(e.APPROVAL)
          },
          {
            label: l(e.SURCHARGE),
            value: e.SURCHARGE,
            hide: !a(e.SURCHARGE) || !i.enableSurcharge
          },
          {
            label: l(e.TRANSFER_TEMPLATE),
            value: e.TRANSFER_TEMPLATE,
            hide: !a(e.TRANSFER_TEMPLATE) || !i.enablePoTemplate
          }
        ]
      },
      {
        label: l(e.SUPPLIER),
        value: e.SUPPLIER,
        hide: !a(e.SUPPLIER)
      },
      {
        label: l(e.WAREHOUSE),
        value: e.WAREHOUSE,
        hide: !a(e.WAREHOUSE)
      },
      {
        label: l(e.PUBLISH),
        value: e.PUBLISH,
        hide: !a(e.PUBLISH)
      },
      {
        label: l(e.IMPORT),
        value: e.IMPORT,
        hide: !a(e.IMPORT) || !i.enableBulkImport
      },
      {
        label: l(e.INTEGRATION),
        value: e.INTEGRATION,
        hide: !a(e.INTEGRATION)
      }
    ], n = I(R(r));
    return ((E = o.currentBusiness.value) == null ? void 0 : E.menuVersion) === "v3" ? n.filter(
      (t) => t.value !== e.INGREDIENTS && t.value !== e.RECIPE && t.value !== e.UNIT && t.value !== e.PUBLISH
    ) : n;
  }), v = T(() => {
    function r(E) {
      for (const t of E)
        if (t.children && t.children.length > 0) {
          const u = r(t.children);
          if (u) return u;
        } else if (t.value)
          return t.value;
    }
    return r(d.value) ?? null;
  });
  return { menuItems: d, firstAccessibleRouteName: v };
}
export {
  p as u
};
