import { defineComponent as C, computed as h, openBlock as l, createElementBlock as d, createElementVNode as r, normalizeClass as v, toDisplayString as m, unref as p, ref as V, resolveComponent as $, Fragment as k, createVNode as E, createCommentVNode as G, withCtx as S, renderList as P } from "vue";
import { useI18n as D, useCoreStore as N } from "@feedmepos/mf-common";
import { u as O } from "./netsuite-BGUUAOqe.js";
function re(e, t = !1) {
  var c;
  return e ? [
    {
      label: t ? e.abbrev : `1 ${e.name} (${e.abbrev})`,
      abbrev: e.abbrev,
      value: null
    },
    ...((c = e.measurements) == null ? void 0 : c.map((o) => ({
      label: t ? o.abbrev : `1 ${o.name} (${o.abbrev})`,
      abbrev: o.abbrev,
      value: o.id
    }))) ?? []
  ] : [];
}
var y = /* @__PURE__ */ ((e) => (e.noInfo = "no-info", e.low = "low", e.mid = "mid", e.high = "high", e))(y || {}), g = /* @__PURE__ */ ((e) => (e.GreaterThan = "GreaterThan", e.GreaterThanOrEqual = "GreaterThanOrEqual", e.Equal = "Equal", e))(g || {});
const A = {
  key: 0,
  class: "flex"
}, U = {
  key: 1,
  class: "flex"
}, H = { class: "flex px-8 py-4 bg-fm-color-neutral-gray-100 fm-corner-radius-md gap-8" }, z = { class: "fm-typo-en-body-md-600 text-fm-color-typo-secondary" }, se = /* @__PURE__ */ C({
  __name: "StockForecast",
  props: {
    days: {},
    level: {},
    operator: {}
  },
  setup(e) {
    const t = e, { t: u } = D(), c = h(() => t.level ? t.level : typeof t.days != "number" ? y.noInfo : t.days > 14 ? y.high : t.days >= 7 && t.days <= 14 ? y.mid : y.low), o = h(() => {
      switch (t.operator) {
        case g.GreaterThan:
          return "inventory.stock.prediction.greaterThanDays";
        case g.GreaterThanOrEqual:
          return "inventory.stock.prediction.greaterThanOrEqualDays";
        case g.Equal:
        default:
          return "inventory.stock.prediction.days";
      }
    });
    return (_, b) => typeof t.days == "number" ? (l(), d("div", A, [
      r("div", {
        class: v([
          `fm-forecast-notification-${c.value}`,
          "flex items-center gap-8 p-4 fm-corner-radius-md fm-typo-en-body-md-600"
        ])
      }, [
        r("div", {
          class: v([
            "fm-forecast-notification-indicator",
            `fm-forecast-notification-indicator-${c.value}`
          ])
        }, null, 2),
        r("div", null, m(p(u)(o.value, [t.days])), 1)
      ], 2)
    ])) : (l(), d("div", U, [
      r("div", H, [
        r("p", z, m(p(u)("inventory.stock.prediction.noData")), 1)
      ])
    ]));
  }
}), R = {
  key: 0,
  class: "flex items-center gap-8"
}, Y = { class: "flex flex-col" }, j = { class: "fm-typo-en-heading-lg-600" }, J = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, K = {
  key: 0,
  class: "fm-typo-en-body-md-400 text-fm-color-system-warning-300"
}, M = {
  key: 1,
  class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
}, Q = { class: "flex flex-col" }, W = { class: "flex flex-col bg-fm-color-bg-secondary font-mono p-4 rounded-md" }, X = { class: "text-fm-color-typo-tertiary flex-shrink-0 fm-typo-en-body-md-400 whitespace-pre flex items-center" }, ne = /* @__PURE__ */ C({
  __name: "SubsidiaryTreeDialog",
  setup(e) {
    const t = V(!1), { t: u } = D(), c = N(), o = O(), _ = h(() => {
      var a;
      return ((a = c.sessionUser.value) == null ? void 0 : a.role.isAdmin) ?? !1;
    });
    function b(a, s = [], i = []) {
      const f = [];
      return a.forEach((n, q) => {
        const B = q === a.length - 1, F = [...s, B];
        let x = "";
        for (let T = 0; T < s.length; T++)
          x += s[T] ? "    " : "│   ";
        x += B ? "└── " : "├── ", f.push({
          id: n.id,
          name: n.name,
          prefix: s.length === 0 ? "" : x,
          isCurrentBusiness: n.id === o.businessSubsidiaryId,
          isRoot: s.length === 0,
          isInPath: i.includes(n.id)
        }), n.children && n.children.length > 0 && f.push(...b(n.children, F, i));
      }), f;
    }
    function w(a, s) {
      return a.map((i) => s.includes(i.id) ? {
        ...i,
        // Recursively filter children
        children: i.children ? w(i.children, s) : []
      } : null).filter(Boolean);
    }
    const I = h(() => {
      if (!o.businessSubsidiaryId)
        return [];
      const a = o.getBusinessSubsidiaryTree(), s = o.getBusinessSubsidiaryPath();
      if (_.value)
        return b(a, [], s);
      const i = w(a, s);
      return b(i, [], s);
    });
    return (a, s) => {
      const i = $("FmButton"), f = $("FmDialog");
      return l(), d(k, null, [
        p(o).isEnabled ? (l(), d("div", R, [
          E(i, {
            "prepend-icon": "info",
            variant: "tertiary",
            onClick: s[0] || (s[0] = (n) => t.value = !0)
          })
        ])) : G("", !0),
        E(f, {
          modelValue: t.value,
          "onUpdate:modelValue": s[1] || (s[1] = (n) => t.value = n),
          "close-button": "",
          dismissAway: ""
        }, {
          "dialog-header": S(() => [
            r("div", Y, [
              r("div", j, m(p(u)("inventory.integration.netsuite.subsidiaryHierarchy.title")), 1),
              r("p", J, m(p(u)("inventory.integration.netsuite.subsidiaryHierarchy.description")), 1),
              _.value ? (l(), d("p", K, " All subsidiaries are shown since you are an admin. ")) : (l(), d("p", M, " Only showing subsidiaries in your business path. ")),
              s[2] || (s[2] = r("div", { class: "flex flex-wrap gap-2 mt-4" }, [
                r("div", { class: "flex items-center gap-2 px-2 py-1 bg-fm-color-bg-brand-secondary rounded-md" }, [
                  r("span", { class: "w-3 h-3 rounded-sm bg-green-400" }),
                  r("span", { class: "fm-typo-en-body-sm-400" }, "Your Business")
                ]),
                r("div", { class: "flex items-center gap-2 px-2 py-1 bg-fm-color-bg-primary rounded-md border border-fm-color-border-secondary" }, [
                  r("span", { class: "w-3 h-3 rounded-sm bg-gray-200 border-2 border-gray-400" }),
                  r("span", { class: "fm-typo-en-body-sm-400" }, "Parent Subsidiary")
                ])
              ], -1))
            ])
          ]),
          default: S(() => [
            r("div", Q, [
              r("div", W, [
                (l(!0), d(k, null, P(I.value, (n) => (l(), d("div", {
                  key: n.id,
                  class: "flex items-stretch"
                }, [
                  r("span", X, m(n.prefix), 1),
                  r("div", {
                    class: v([
                      "px-2 py-1 rounded-md flex-1",
                      n.isCurrentBusiness ? "border-2 bg-green-200 border-green-400" : n.isInPath ? "border-2 bg-gray-200 border-gray-400" : "bg-fm-color-bg-primary border border-fm-color-border-secondary"
                    ])
                  }, [
                    r("span", {
                      class: v([
                        n.isCurrentBusiness || n.isInPath ? "fm-typo-en-body-md-600 text-fm-color-typo-primary" : "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
                      ])
                    }, m(n.name), 3)
                  ], 2)
                ]))), 128))
              ])
            ])
          ]),
          _: 1
        }, 8, ["modelValue"])
      ], 64);
    };
  }
});
export {
  y as S,
  se as _,
  ne as a,
  re as g
};
