import { defineComponent as S, computed as w, ref as P, resolveComponent as h, openBlock as n, createElementBlock as p, createVNode as x, withCtx as $, createElementVNode as b, Fragment as V, createTextVNode as R, toDisplayString as D, unref as r, createBlock as v, createCommentVNode as k, renderList as N, watch as O, mergeModels as H, useModel as I, renderSlot as W, normalizeClass as A } from "vue";
import { useCoreStore as q, useI18n as Q } from "@feedmepos/mf-common";
import { u as G } from "./app-Bpb4394e.js";
import { b as T } from "./date2-DpnYOzUg.js";
import { useBreakpoints as J } from "@feedmepos/ui-library";
import { u as K } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-sUxHOj47.js";
import { D as z } from "./app-DiX-EfV6.js";
import { F as X } from "./FmAdminBadge-DjnBAgyv.js";
const Z = { class: "inline-flex" }, ee = { class: "inline-flex rounded-md items-center gap-4 justify-center h-[30px] px-8 py-4 bg-fm-color-neutral-gray-100 cursor-pointer text-fm-color-neutral-gray-400" }, oe = { class: "fm-typo-en-body-md-600 select-none text-ellipsis overflow-hidden whitespace-nowrap" }, te = { class: "relative" }, ne = { class: "sticky top-0 py-8 bg-white translate-y-[-12px]" }, le = /* @__PURE__ */ S({
  __name: "ChangeLocationComponent",
  props: {
    showBusiness: { type: Boolean }
  },
  setup(i) {
    const t = G(), m = q(), c = w(() => {
      var e;
      return (e = m.currentBusiness.value) == null ? void 0 : e.name;
    }), { t: f } = Q(), d = P(""), a = w({
      get() {
        return t.businessLevel;
      },
      set(e) {
        t.businessLevel = e;
      }
    }), y = w(
      () => t.locations.map((e) => ({
        label: e.name,
        value: e.dbName,
        type: e.type,
        code: e.doc.profile.code ?? "--"
      })).filter((e) => {
        var g;
        if (!d.value) return !0;
        const o = d.value.toLocaleLowerCase();
        return e.label.toLocaleLowerCase().includes(o) || ((g = e.code) == null ? void 0 : g.toLocaleLowerCase().includes(o));
      })
    ), l = w(
      () => y.value.filter((e) => e.type === "restaurant")
    ), s = w(
      () => y.value.filter((e) => e.type === "warehouse")
    );
    function M({ value: e }) {
      a.value = !1, t.selectLocation(t.locations.find((o) => o.dbName === e));
    }
    return (e, o) => {
      const g = h("FmIcon"), j = h("FmSearch"), C = h("FmMenuItem"), E = h("FmMenu");
      return n(), p("div", Z, [
        x(E, { "close-on-click": !0 }, {
          "menu-button": $(() => [
            b("div", ee, [
              x(g, {
                name: e.showBusiness && a.value ? "store" : "storefront",
                size: "sm"
              }, null, 8, ["name"]),
              b("div", oe, [
                e.showBusiness && a.value ? (n(), p(V, { key: 0 }, [
                  R(D(c.value), 1)
                ], 64)) : r(t)._currentLocation ? (n(), p(V, { key: 1 }, [
                  R(D(r(t)._currentLocation.name) + " (" + D(r(t)._currentLocation.doc.profile.code ?? "--") + ") ", 1)
                ], 64)) : (n(), p(V, { key: 2 }, [
                  R(D(r(f)("inventory.common.noLocationSelected")), 1)
                ], 64))
              ]),
              x(g, {
                name: "expand_more",
                size: "sm"
              })
            ])
          ]),
          default: $(() => [
            b("div", te, [
              b("div", ne, [
                x(j, {
                  "model-value": d.value,
                  "onUpdate:modelValue": o[0] || (o[0] = (u) => d.value = u),
                  placeholder: r(f)("inventory.common.table.toolbar.filterItems")
                }, null, 8, ["model-value", "placeholder"])
              ]),
              b("div", null, [
                e.showBusiness ? (n(), v(C, {
                  key: 0,
                  "model-value": a.value,
                  label: c.value,
                  sublabel: "Business",
                  onClick: o[1] || (o[1] = (u) => a.value = !0)
                }, null, 8, ["model-value", "label"])) : k("", !0),
                (n(!0), p(V, null, N(l.value, (u) => {
                  var F;
                  return n(), v(C, {
                    key: u.value,
                    "model-value": !a.value && ((F = r(t)._currentLocation) == null ? void 0 : F.dbName) === u.value,
                    label: `${u.label} (${u.code})`,
                    sublabel: "Restaurant",
                    onClick: (_) => M(u),
                    onVnodeMounted: (_) => {
                      var B, L, U;
                      return !a.value && ((B = r(t)._currentLocation) == null ? void 0 : B.dbName) === u.value && ((L = _.el) == null || L.scrollIntoView({ behavior: "instant", block: "end" }), (U = _.el) == null || U.scrollIntoView({ behavior: "smooth", block: "center" })), void 0;
                    }
                  }, null, 8, ["model-value", "label", "onClick", "onVnodeMounted"]);
                }), 128)),
                (n(!0), p(V, null, N(s.value, (u) => {
                  var F;
                  return n(), v(C, {
                    key: u.value,
                    "model-value": !a.value && ((F = r(t)._currentLocation) == null ? void 0 : F.dbName) === u.value,
                    label: u.label,
                    sublabel: "Warehouse",
                    onClick: (_) => M(u),
                    onVnodeMounted: (_) => {
                      var B, L;
                      return !a.value && ((B = r(t)._currentLocation) == null ? void 0 : B.dbName) === u.value && ((L = _.el) == null || L.scrollIntoView({ behavior: "smooth", block: "center" })), void 0;
                    }
                  }, null, 8, ["model-value", "label", "onClick", "onVnodeMounted"]);
                }), 128)),
                !e.showBusiness && !l.value.length && !s.value.length ? (n(), v(C, {
                  key: 1,
                  disabled: "",
                  label: r(f)("inventory.common.noResultFound")
                }, null, 8, ["label"])) : k("", !0)
              ])
            ])
          ]),
          _: 1
        })
      ]);
    };
  }
});
function we() {
  const i = /* @__PURE__ */ new Date();
  return i.setDate(i.getDate() - 15), {
    start: i,
    end: /* @__PURE__ */ new Date()
  };
}
function Y(i = 15) {
  const t = /* @__PURE__ */ new Date();
  t.setDate(t.getDate() - i);
  const m = t, c = /* @__PURE__ */ new Date();
  return {
    startDate: `${T(m)}`,
    endDate: `${T(c)}`
  };
}
const ae = { class: "inline-flex rounded-md items-center gap-4 justify-center h-[30px] px-8 py-4 bg-fm-color-neutral-gray-100 cursor-pointer text-fm-color-neutral-gray-400" }, se = { class: "fm-typo-en-body-md-600 select-none text-ellipsis overflow-hidden whitespace-nowrap" }, re = /* @__PURE__ */ S({
  __name: "FmDateRangePickerChip",
  props: {
    modelValue: { default: (i) => i.modelValue ?? Y() }
  },
  emits: ["update:modelValue"],
  setup(i, { emit: t }) {
    const m = t, c = P(Y());
    O(c, (d) => {
      m("update:modelValue", d);
    });
    const f = w(() => {
      const { startDate: d, endDate: a } = c.value;
      return !d && !a ? "" : `${d} - ${a}`;
    });
    return (d, a) => {
      const y = h("FmIcon"), l = h("FmDateRangePicker");
      return n(), v(l, {
        "show-predefined-range": "",
        modelValue: c.value,
        "onUpdate:modelValue": a[0] || (a[0] = (s) => c.value = s),
        "start-label": "",
        "end-label": ""
      }, {
        "trigger-button": $(() => [
          b("div", ae, [
            x(y, {
              name: "calendar_month",
              size: "sm"
            }),
            b("div", se, D(f.value), 1)
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), ue = { class: "flex-1 w-full flex items-center gap-4 xs:flex-col-reverse sm:flex-col-reverse" }, ie = {
  key: 0,
  class: "flex-1 xs:w-full sm:w-full"
}, de = {
  key: 1,
  class: "flex-1"
}, ce = { class: "w-full max-w-[343px] xs:max-w-[unset] sm:max-w-[unset]" }, ke = /* @__PURE__ */ S({
  __name: "FmInventoryTableToolbar",
  props: /* @__PURE__ */ H({
    dateRangeQuery: { type: Boolean },
    changeLocation: { type: Boolean },
    searchable: { type: Boolean },
    hideFilterOptions: { type: Boolean },
    filterable: { type: Boolean },
    filterAttributes: {},
    actions: {},
    usingBusinessHelperText: {},
    showBusiness: { type: Boolean }
  }, {
    search: {},
    searchModifiers: {},
    filter: {},
    filterModifiers: {},
    dateRange: {},
    dateRangeModifiers: {}
  }),
  emits: ["update:search", "update:filter", "update:dateRange"],
  setup(i) {
    const { breakpoints: t } = J(), m = w(() => t.value.xs || t.value.sm), c = I(i, "search"), f = I(i, "filter"), d = I(i, "dateRange"), { t: a } = Q(), y = K();
    return (l, s) => {
      const M = h("FmTextField"), e = h("FmButton");
      return n(), p("div", {
        class: "flex flex-col gap-8",
        onVnodeMounted: s[4] || (s[4] = //@ts-ignore
        (...o) => r(y).onMounted && r(y).onMounted(...o)),
        onVnodeUnmounted: s[5] || (s[5] = //@ts-ignore
        (...o) => r(y).onUnmounted && r(y).onUnmounted(...o))
      }, [
        W(l.$slots, "default"),
        b("div", {
          class: A([
            "flex gap-8 items-center",
            {
              "px-8 flex-col-reverse h-[unset]": m.value,
              "h-48": !m.value
            }
          ])
        }, [
          l.changeLocation || l.dateRangeQuery ? (n(), p("div", {
            key: 0,
            class: A([
              "flex gap-8 items-center",
              {
                "w-full overflow-x-auto": m.value
              }
            ])
          }, [
            l.changeLocation ? (n(), v(le, {
              key: 0,
              "show-business": l.showBusiness
            }, null, 8, ["show-business"])) : k("", !0),
            l.dateRangeQuery ? (n(), v(re, {
              key: 1,
              "model-value": d.value,
              "onUpdate:modelValue": s[0] || (s[0] = (o) => d.value = o)
            }, null, 8, ["model-value"])) : k("", !0)
          ], 2)) : k("", !0),
          b("div", ue, [
            l.filterable && l.filterAttributes ? (n(), p("div", ie, [
              l.hideFilterOptions ? (n(), v(X, { key: 1 }, {
                default: $(() => [
                  x(r(z), {
                    modelValue: f.value,
                    "onUpdate:modelValue": s[2] || (s[2] = (o) => f.value = o),
                    attributes: l.filterAttributes
                  }, null, 8, ["modelValue", "attributes"])
                ]),
                _: 1
              })) : (n(), v(r(z), {
                key: 0,
                modelValue: f.value,
                "onUpdate:modelValue": s[1] || (s[1] = (o) => f.value = o),
                attributes: l.filterAttributes
              }, null, 8, ["modelValue", "attributes"]))
            ])) : m.value ? k("", !0) : (n(), p("div", de)),
            b("div", ce, [
              l.searchable ? (n(), v(M, {
                key: 0,
                "model-value": c.value,
                "onUpdate:modelValue": s[3] || (s[3] = (o) => c.value = o),
                "prepend-icon": "search",
                placeholder: r(a)("inventory.common.table.toolbar.filterItems"),
                class: "w-full"
              }, null, 8, ["model-value", "placeholder"])) : k("", !0)
            ]),
            (n(!0), p(V, null, N(l.actions, (o, g) => (n(), v(e, {
              key: g,
              variant: "tertiary",
              "prepend-icon": o.icon,
              onClick: o.onClick
            }, null, 8, ["prepend-icon", "onClick"]))), 128))
          ])
        ], 2)
      ], 512);
    };
  }
});
export {
  ke as _,
  we as a,
  Y as i
};
