import { ref as F, computed as h, defineComponent as N, resolveComponent as O, createBlock as I, openBlock as m, withCtx as T, createElementVNode as g, createVNode as d, unref as a, createElementBlock as k, Fragment as pe, renderList as we, createCommentVNode as M, normalizeClass as ve, toDisplayString as K, withModifiers as fe, mergeModels as Ze, useModel as Xe, renderSlot as _e, watch as de, createTextVNode as et, watchEffect as tt, nextTick as Ae, resolveDynamicComponent as lt, onMounted as at, h as q, isRef as je, normalizeStyle as ft } from "vue";
import { u as Fe, T as Ce, B as me, I as Re, J as ge, V as gt, af as bt, ag as _t, ah as Pe, ai as yt, R as ht, a5 as be, aj as Ee } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
import { useI18n as Ie, useCoreStore as ze, useCustomAttributes as xt } from "@feedmepos/mf-common";
import { u as Se } from "./menu-DNLXOwiM.js";
import { L as Ge } from "./LinkProductSideSheet-DUHaljek.js";
import { r as Ct, _ as Le } from "./index-BMZylPL8.js";
import { _ as Me, a as qe } from "./CustomAttributeChip.vue_vue_type_script_setup_true_lang-BrZhfy-j.js";
import { _ as Ue, u as kt } from "./Thumbnail.vue_vue_type_script_setup_true_lang-ChJOXWkd.js";
import { f as wt, o as St, a as Vt, m as Ft } from "./menuV2-Da02vc32.js";
import { u as ot, C as It } from "./item-BZS28ZS_.js";
import { b as We, H as $t } from "./app-5fxKLAzS.js";
import { useBreakpoints as rt, components as te, useDialog as Tt, FmButtonColorThemeVariant as W, FmButtonVariant as ee } from "@feedmepos/ui-library";
import { F as Pt } from "./index-CisutoS9.js";
import { _ as De, a as At } from "./app-D-J2cjak.js";
import { _ as ke } from "./TextChip.vue_vue_type_script_setup_true_lang-8frWuZFL.js";
import { _ as Rt } from "./index-4cR8a2UZ.js";
import { r as Mt, _ as Ut } from "./ImportProductDialog.vue_vue_type_script_setup_true_lang-loNz40wt.js";
import { c as zt } from "./check-C9mY6LiX.js";
import { f as Dt } from "./currency-DBI5JSrw.js";
import { w as Ot } from "./tooltip-B5BiPMx9.js";
function Bt(C, e, i = C) {
  const n = F(!0), t = h(() => {
    if (!n.value && !e.value)
      return !0;
    if (e.value && e.value.length > 0) {
      const f = i.value.map((s) => s.value);
      return e.value.length === f.length && e.value.every((s) => f.includes(s));
    }
    return !1;
  }), u = h(() => {
    var f, s, b, y;
    return !!((f = e.value) != null && f.length && ((s = e.value) == null ? void 0 : s.length) > 0 && ((b = e.value) == null ? void 0 : b.length) < ((y = C.value) == null ? void 0 : y.length));
  });
  return { allCleared: n, allSelected: t, indeterminate: u, toggleAll: () => {
    if (t.value) {
      e.value = void 0, n.value = !0;
      return;
    }
    const f = i.value.map((s) => s.value);
    f.length === C.value.length ? (e.value = void 0, n.value = !1) : (e.value = f, n.value = !1);
  }, toggleOption: (f) => {
    var b, y, w;
    let s;
    e.value === void 0 && n.value ? s = [f] : e.value === void 0 && !n.value ? s = (b = C.value.map((z) => z.value)) == null ? void 0 : b.filter((z) => z !== f) : (y = e.value) != null && y.includes(f) ? s = (w = e.value) == null ? void 0 : w.filter((z) => z !== f) : s = [...e.value || [], f], s.length === 0 ? (e.value = void 0, n.value = !0) : s.length === C.value.length ? (e.value = void 0, n.value = !1) : e.value = s;
  } };
}
const Kt = { class: "inline-flex items-center" }, Nt = {
  key: 0,
  class: /* @__PURE__ */ ve([
    "fm-typo-en-body-md-600 select-none text-ellipsis overflow-hidden whitespace-nowrap",
    "text-fm-color-neutral-gray-400"
  ])
}, jt = { class: "p-4" }, Et = { class: "flex-1 overflow-y-auto min-h-0" }, He = /* @__PURE__ */ N({
  __name: "CategorySelector",
  emits: ["toggleAttributeFilter"],
  setup(C, { emit: e }) {
    const i = e, n = Fe(), { categories: t, selectedCategories: u } = Se(), l = h(() => n.state.currentCategoryIds), v = h(
      () => t.value.map((B) => ({ label: B.name, value: B.id }))
    ), f = h(() => v.value.filter(
      (B) => B.label.toLowerCase().includes(y.value.toLowerCase())
    )), { t: s } = Ie(), b = h(() => {
      var B, D, H;
      return t.value.length === ((B = u.value) == null ? void 0 : B.length) ? s("menu.category.selector.all") : ((D = u.value) == null ? void 0 : D.length) === 1 ? u.value[0].name : `${(H = u.value) == null ? void 0 : H.length}`;
    }), y = F(""), w = h({
      get: () => l.value,
      set: (B) => {
        n.selectCategory(B);
      }
    }), { allSelected: z, toggleAll: Y, toggleOption: S, indeterminate: oe } = Bt(
      v,
      w,
      f
    ), J = ze(), re = h(() => J.itemAttributeSettings.value.length > 0);
    function G() {
      i("toggleAttributeFilter");
    }
    return (B, D) => {
      const H = O("FmIcon"), Z = O("FmChip"), ne = O("FmSearch"), Q = O("FmMenuItem"), se = O("FmMenu");
      return m(), I(se, {
        "close-on-click": !1,
        width: 220
      }, {
        "menu-button": T(() => [
          g("div", Kt, [
            d(Z, null, {
              default: T(() => [
                b.value ? (m(), k("div", Nt, K(a(s)("menu.category.selector.title", { label: b.value })), 1)) : M("", !0),
                d(H, {
                  color: "neutral-gray-400",
                  name: "expand_more",
                  size: "sm"
                }),
                re.value ? (m(), k("div", {
                  key: 1,
                  class: "pl-8 flex items-center justify-center border-l border-fm-color-neutral-gray-200",
                  onClick: fe(G, ["stop"])
                }, [
                  d(H, {
                    name: "filter_alt",
                    outline: "",
                    color: "neutral-gray-400",
                    size: "sm",
                    onClick: D[0] || (D[0] = fe(() => {
                    }, ["prevent"]))
                  })
                ])) : M("", !0)
              ]),
              _: 1
            })
          ])
        ]),
        default: T(() => [
          g("div", jt, [
            d(ne, {
              autofocus: "",
              modelValue: y.value,
              "onUpdate:modelValue": D[1] || (D[1] = (R) => y.value = R),
              placeholder: a(s)("menu.common.actions.search")
            }, null, 8, ["modelValue", "placeholder"])
          ]),
          g("div", Et, [
            d(Q, {
              label: "All",
              "has-checkbox": "",
              "model-value": a(z),
              indeterminate: a(oe),
              onClick: a(Y)
            }, null, 8, ["model-value", "indeterminate", "onClick"]),
            (m(!0), k(pe, null, we(f.value, (R) => {
              var $;
              return m(), I(Q, {
                key: R.value || "",
                label: R.label,
                "has-checkbox": "",
                "model-value": a(z) || (($ = w.value) == null ? void 0 : $.includes(R.value)),
                onClick: (P) => a(S)(R.value)
              }, null, 8, ["label", "model-value", "onClick"]);
            }), 128))
          ])
        ]),
        _: 1
      });
    };
  }
}), Gt = { class: "flex flex-wrap gap-8" }, Lt = { class: "py-12 px-16 space-y-12" }, qt = { class: "fm-typo-en-body-md-600 text-fm-color-neutral-gray-600" }, Wt = { class: "flex flex-wrap gap-8" }, Ht = {
  key: 0,
  class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
}, Qt = { key: 0 }, Yt = {
  key: 1,
  class: "inline-block w-8"
}, Jt = { key: 0 }, Zt = { key: 1 }, Qe = /* @__PURE__ */ N({
  __name: "CategoriesChip",
  props: {
    categories: { default: () => [] },
    ellipsis: { type: Boolean, default: !0 }
  },
  setup(C) {
    const e = C, { t: i } = Ie(), n = rt(), t = h(() => n.breakpoints.value.xs), u = h(() => e.ellipsis ? t.value ? 1 : 2 : 1 / 0), l = h(() => e.categories.length <= u.value ? e.categories : e.categories.slice(0, u.value)), v = F(!0), f = h(() => {
      if (v.value) {
        const b = l.value.join(", ");
        return b.length > 20 ? b.slice(0, 20) + "..." : b;
      }
      return e.categories.join(", ");
    });
    return (s, b) => {
      const y = O("FmTooltip");
      return t.value ? (m(), k(pe, { key: 1 }, [
        s.categories.length > 0 ? (m(), k("p", Ht, [
          g("span", null, K(a(i)("menu.product.table.columns.category")) + ": ", 1),
          g("span", null, K(f.value), 1),
          v.value ? (m(), k("span", Yt)) : (m(), k("br", Qt)),
          s.categories.length > u.value ? (m(), k("span", {
            key: 2,
            class: "fm-typo-en-body-md-400 text-fm-color-primary cursor-pointer",
            onClick: b[0] || (b[0] = fe((w) => v.value = !v.value, ["stop", "prevent"]))
          }, [
            v.value ? (m(), k("span", Jt, K(a(i)("menu.product.table.category.expand", { count: s.categories.length - u.value })), 1)) : (m(), k("span", Zt, K(a(i)("menu.product.table.category.collapse")), 1))
          ])) : M("", !0)
        ])) : M("", !0)
      ], 64)) : (m(), I(y, {
        key: 0,
        class: "flex",
        variant: "rich",
        placement: "top",
        "z-index": 50
      }, {
        content: T(() => [
          g("div", Lt, [
            g("p", qt, K(a(i)("menu.product.table.category.all")), 1),
            g("div", Wt, [
              (m(!0), k(pe, null, we(e.categories, (w) => (m(), I(ke, {
                key: w,
                label: w,
                variant: "neutral"
              }, null, 8, ["label"]))), 128))
            ])
          ])
        ]),
        default: T(() => [
          g("div", Gt, [
            (m(!0), k(pe, null, we(l.value, (w) => (m(), I(ke, {
              key: w,
              label: w,
              variant: "neutral"
            }, null, 8, ["label"]))), 128)),
            s.categories.length > u.value ? (m(), I(ke, {
              key: 0,
              label: "...",
              variant: "neutral"
            })) : M("", !0)
          ])
        ]),
        _: 1
      }));
    };
  }
}), Xt = /* @__PURE__ */ N({
  __name: "ProductSearcher",
  props: /* @__PURE__ */ Ze({
    label: {},
    helperText: {},
    menu: {}
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(C) {
    const e = C, i = Xe(C, "modelValue"), n = h(() => e.menu.modules.item.map((t) => ({
      label: t.code ? `${t.code} ${t.name}` : t.name,
      value: t._id
    })));
    return (t, u) => {
      const l = O("FmSelect");
      return m(), I(l, {
        modelValue: i.value,
        "onUpdate:modelValue": u[0] || (u[0] = (v) => i.value = v),
        items: n.value,
        searchable: !0,
        "search-target": "label",
        placeholder: "Search by product name or code",
        label: t.label,
        "helper-text": t.helperText
      }, null, 8, ["modelValue", "items", "label", "helper-text"]);
    };
  }
}), el = { class: "flex" }, tl = { class: "w-[260px] space-y-16 h-full" }, ll = { class: "flex items-center gap-4 px-8" }, al = { class: "fm-typo-en-title-sm-600" }, ol = {
  key: 0,
  class: "bg-fm-color-neutral-gray-100 rounded-md px-8 py-4"
}, rl = { class: "fm-typo-en-body-md-600" }, nl = { class: "flex-1" }, nt = /* @__PURE__ */ N({
  __name: "ViewLayout",
  props: /* @__PURE__ */ Ze({
    title: {},
    titleBadge: {},
    items: {}
  }, {
    modelValue: { required: !0 },
    modelModifiers: {}
  }),
  emits: ["update:modelValue"],
  setup(C) {
    const e = Xe(C, "modelValue");
    return (i, n) => {
      const t = O("FmCollapsibleTabs");
      return m(), k("div", el, [
        g("div", tl, [
          g("div", ll, [
            g("p", al, K(i.title), 1),
            i.titleBadge !== void 0 ? (m(), k("div", ol, [
              g("p", rl, K(i.titleBadge), 1)
            ])) : M("", !0)
          ]),
          d(De, null, {
            default: T(() => [
              d(t, {
                modelValue: e.value,
                "onUpdate:modelValue": n[0] || (n[0] = (u) => e.value = u),
                items: i.items
              }, null, 8, ["modelValue", "items"])
            ]),
            _: 1
          })
        ]),
        n[1] || (n[1] = g("div", { class: "w-[1px] min-h-full ml-4 mr-12 bg-fm-color-neutral-gray-100 self-stretch" }, null, -1)),
        g("div", nl, [
          _e(i.$slots, "default")
        ])
      ]);
    };
  }
}), Ve = /* @__PURE__ */ N({
  __name: "OrderFromChip",
  props: {
    orderFrom: {}
  },
  setup(C) {
    const e = C, i = Ce();
    return (n, t) => {
      var u, l;
      return m(), I(ke, {
        label: ((u = a(i)[e.orderFrom]) == null ? void 0 : u.label) || e.orderFrom,
        variant: (l = a(i)[e.orderFrom]) == null ? void 0 : l.variant
      }, null, 8, ["label", "variant"]);
    };
  }
}), sl = /* @__PURE__ */ N({
  __name: "GroupViewTable",
  props: {
    data: {}
  },
  setup(C) {
    const e = C, i = [{
      accessorKey: "code",
      header: () => "Code",
      enableSorting: !1,
      cell: ({
        row: l
      }) => {
        const v = l.original;
        return v.subRows ? d("div", {
          class: "flex items-center gap-2 fm-typo-en-body-md-600 text-fm-color-typo-secondary"
        }, [d(te.FmButton, {
          icon: "keyboard_arrow_up",
          variant: "tertiary",
          class: ["cursor-pointer", "transition-transform", l.getIsExpanded() ? "transform rotate-180" : ""],
          onClick: l.getToggleExpandedHandler()
        }, null), et("Found in group: "), v.groupName]) : v.code;
      },
      meta: {
        colspan: (l) => l.original.subRows ? 5 : 1
      }
    }, {
      accessorKey: "productName",
      header: () => "Product name",
      enableSorting: !1,
      meta: {
        colspan: (l) => l.original.subRows ? 0 : 1
      }
    }, {
      accessorKey: "variant",
      header: () => "Variant",
      enableSorting: !1,
      meta: {
        colspan: (l) => l.original.subRows ? 0 : 1
      }
    }, {
      accessorKey: "price",
      header: () => "Price",
      enableSorting: !1,
      meta: {
        colspan: (l) => l.original.subRows ? 0 : 1
      }
    }, {
      accessorKey: "orderFrom",
      header: () => "Order from",
      enableSorting: !1,
      cell: (l) => {
        const v = l.row.original;
        return d(Ve, {
          orderFrom: v.orderFrom ?? ""
        }, null);
      },
      meta: {
        colspan: (l) => l.original.subRows ? 0 : 1
      }
    }], n = F({}), t = (l) => l.subRows;
    function u() {
      n.value = Object.fromEntries(e.data.map((l, v) => [v, !0]));
    }
    return de(() => e.data, () => {
      u();
    }), (l, v) => {
      const f = O("FmTable");
      return m(), I(De, null, {
        default: T(() => [d(f, {
          "column-defs": i,
          "row-data": l.data,
          "hide-footer": !0,
          "page-size": 1e6,
          "get-sub-row": t,
          "expanded-state": n.value,
          "shrink-at": !1,
          "onUpdate:expandedState": v[0] || (v[0] = (s) => n.value = s)
        }, null, 8, ["row-data", "expanded-state"])]),
        _: 1
      });
    };
  }
}), ul = /* @__PURE__ */ N({
  __name: "GroupView",
  props: {
    itemId: {},
    menu: {}
  },
  setup(C) {
    const e = C, i = F(""), n = h(() => t.value.reduce((s, b) => s + (typeof b.badge == "number" ? b.badge ?? 1 : 0), 0)), t = F([]), u = h(() => {
      const s = t.value.find((y) => y.value === i.value);
      return ((s == null ? void 0 : s.itemInGroup) || []).map((y) => ({
        groupName: y.group.name,
        subRows: y.items.map((w) => ({
          // @ts-ignore
          code: w.code || w.fallbackCode,
          productName: w.combinationKey ? "" : w.name ?? "",
          price: w.price ? me.Dinero.fromFdoDinero(w.price).toFormat() : "--",
          orderFrom: w.orderFrom ?? void 0,
          variant: w.combinationKey ? w.name ?? "" : void 0
        }))
      }));
    });
    function l() {
      return [{
        label: "Master product",
        value: "",
        catalogId: null,
        data: [],
        disabled: !1,
        badge: void 0,
        itemInGroup: []
      }, ...e.menu.modules.catalog.map((b) => ({
        label: b.name,
        value: b._id,
        catalogId: b._id,
        data: [],
        disabled: !1,
        badge: void 0,
        itemInGroup: []
      }))];
    }
    h(() => t.value.find((s) => s.value === i.value));
    async function v(s) {
      const b = t.value.find((y) => y.catalogId === s);
      if (b) {
        b.badge = () => d(te.FmCircularProgress, {
          size: "md"
        }, null);
        const y = await wt(Re(e.menu), s, e.itemId);
        b.badge = y.length, b.disabled = y.length <= 0, b.itemInGroup = y;
      }
    }
    function f() {
      t.value = l(), t.value.forEach((s) => {
        v(s.catalogId);
      });
    }
    return de([() => e.menu, () => e.itemId], () => {
      e.menu && e.itemId && f();
    }, {
      immediate: !0
    }), (s, b) => (m(), I(nt, {
      modelValue: i.value,
      "onUpdate:modelValue": b[0] || (b[0] = (y) => i.value = y),
      items: t.value,
      title: "Catalog",
      "title-badge": n.value
    }, {
      default: T(() => [d(sl, {
        data: u.value
      }, null, 8, ["data"])]),
      _: 1
    }, 8, ["modelValue", "items", "title-badge"]));
  }
}), il = {
  class: "scroll-x-auto"
}, cl = /* @__PURE__ */ N({
  __name: "ProductViewTable",
  props: {
    itemId: {},
    menu: {},
    catalogId: {},
    schedulerIds: {}
  },
  setup(C) {
    const e = C, i = [{
      accessorKey: "scheduler",
      header: () => "Scheduler",
      enableSorting: !1,
      cell: (u) => {
        const l = u.row.original, v = l.loading ? d(te.FmCircularProgress, {
          size: "md"
        }, null) : null;
        return d("div", {
          class: "flex items-center gap-2"
        }, [l.scheduler, v]);
      }
    }, {
      accessorKey: "code",
      header: () => "Code",
      enableSorting: !1
    }, {
      accessorKey: "productName",
      header: () => "Product name",
      enableSorting: !1
    }, {
      accessorKey: "price",
      header: () => "Price",
      enableSorting: !1
    }, {
      accessorKey: "orderFrom",
      header: () => "Order from",
      cell: (u) => {
        const l = u.row.original;
        return d(Ve, {
          orderFrom: l.orderFrom
        }, null);
      },
      enableSorting: !1
    }], n = F([]);
    function t(u, l) {
      return {
        loading: !0,
        schedulerId: u,
        scheduler: l,
        code: "--",
        productName: "--",
        price: "--",
        orderFrom: "--"
      };
    }
    return de([() => e.menu, () => e.catalogId, () => e.schedulerIds], async () => {
      n.value = [t(null, "All day"), ...e.schedulerIds.map((u) => {
        var l;
        return t(u, ((l = e.menu.modules.scheduler.find((v) => v._id === u)) == null ? void 0 : l.name) || "Unknown");
      })], n.value.forEach(async (u) => {
        const v = (await St(Re(e.menu), e.catalogId, u.schedulerId)).modules.item.find((s) => s._id === e.itemId), f = n.value.findIndex((s) => s.schedulerId === u.schedulerId);
        if (v) {
          const s = Re(n.value);
          s[f].loading = !1, s[f].code = v.code || "--", s[f].productName = v.name || "--", s[f].price = me.Dinero.fromFdoDinero(v.price).toFormat(), s[f].orderFrom = v.orderFrom || "--", n.value = s;
        }
      });
    }), (u, l) => {
      const v = O("FmTable");
      return m(), I(De, null, {
        default: T(() => [g("div", il, [d(v, {
          class: "min-w-[800px]",
          "column-defs": i,
          "row-data": n.value,
          "hide-footer": !0,
          "page-size": n.value.length,
          "shrink-at": !1
        }, null, 8, ["row-data", "page-size"])])]),
        _: 1
      });
    };
  }
}), dl = /* @__PURE__ */ N({
  __name: "ProductView",
  props: {
    itemId: {},
    menu: {}
  },
  setup(C) {
    const e = C, i = F(null);
    tt(async () => {
      i.value = await Vt(e.menu, e.itemId), await Ae(), n.value = t.value[0].value;
    });
    const n = F(""), t = h(() => {
      var f, s;
      const l = {
        label: "Master product",
        value: "",
        catalogId: null,
        badge: (((f = i.value) == null ? void 0 : f.schedulers.length) || 0) + 1,
        schedulerIds: (s = i.value) == null ? void 0 : s.schedulers
      };
      if (!i.value)
        return [l];
      const v = e.menu.modules.catalog.map((b) => {
        const y = i.value.catalogs[b._id];
        return {
          label: b.name,
          value: b._id,
          disabled: !y,
          catalogId: b._id,
          badge: y ? ((y == null ? void 0 : y.schedulers.length) || 0) + 1 : 0,
          schedulerIds: y == null ? void 0 : y.schedulers
        };
      });
      return [l, ...v];
    }), u = h(() => t.value.find((l) => l.value === n.value));
    return (l, v) => (m(), I(nt, {
      modelValue: n.value,
      "onUpdate:modelValue": v[0] || (v[0] = (f) => n.value = f),
      items: t.value,
      title: "Catalog",
      "title-badge": t.value.filter((f) => !f.disabled).length
    }, {
      default: T(() => {
        var f, s;
        return [
          d(cl, {
            menu: l.menu,
            "item-id": l.itemId,
            "catalog-id": ((f = u.value) == null ? void 0 : f.catalogId) || null,
            "scheduler-ids": ((s = u.value) == null ? void 0 : s.schedulerIds) || []
          }, null, 8, ["menu", "item-id", "catalog-id", "scheduler-ids"])
        ];
      }),
      _: 1
    }, 8, ["modelValue", "items", "title-badge"]));
  }
}), ml = { class: "flex items-center gap-8" }, pl = { class: "space-y-4" }, vl = { class: "fm-typo-en-title-md-600" }, fl = { key: 0 }, gl = { class: "text-fm-color-typo-secondary" }, bl = {
  key: 0,
  class: "text-fm-color-typo-secondary"
}, _l = { class: "flex items-center gap-4" }, yl = /* @__PURE__ */ N({
  __name: "ProductBaseInfo",
  props: {
    itemId: {},
    menu: {}
  },
  setup(C) {
    const e = C, i = h(() => e.menu.modules.item.find((t) => t._id === e.itemId)), n = h(() => {
      var t;
      return me.Dinero.fromFdoDinero((t = i.value) == null ? void 0 : t.price).toFormat(!0);
    });
    return (t, u) => {
      var l, v, f, s, b, y, w;
      return m(), k("div", ml, [
        d(Ue, {
          alt: ((l = i.value) == null ? void 0 : l.name) ?? null,
          size: 72,
          src: (v = i.value) == null ? void 0 : v.thumbnail,
          crossorigin: !1
        }, null, 8, ["alt", "src"]),
        g("div", pl, [
          g("p", vl, [
            (f = i.value) != null && f.code ? (m(), k("span", fl, K((s = i.value) == null ? void 0 : s.code) + ", ", 1)) : M("", !0),
            g("span", null, K((b = i.value) == null ? void 0 : b.name), 1)
          ]),
          g("p", gl, "Base price: " + K(n.value), 1),
          (y = i.value) != null && y.customAttributes ? (m(), k("div", bl, [
            g("div", _l, [
              u[0] || (u[0] = g("span", null, "Tagging:", -1)),
              d(Me, {
                ellipsis: !1,
                "custom-attributes": (w = i.value) == null ? void 0 : w.customAttributes
              }, null, 8, ["custom-attributes"])
            ])
          ])) : M("", !0)
        ])
      ]);
    };
  }
}), hl = { class: "space-y-16" }, xl = /* @__PURE__ */ N({
  __name: "ProductViewer",
  props: {
    itemId: {},
    menu: {}
  },
  setup(C) {
    const e = F("product"), i = h(() => [
      {
        value: "product",
        label: "Product",
        component: dl
      },
      {
        value: "group",
        label: "Group",
        component: ul
      }
    ]);
    return (n, t) => {
      var l;
      const u = O("FmTabs");
      return m(), k("div", hl, [
        d(yl, {
          "item-id": n.itemId,
          menu: n.menu
        }, null, 8, ["item-id", "menu"]),
        g("div", null, [
          d(u, {
            modelValue: e.value,
            "onUpdate:modelValue": t[0] || (t[0] = (v) => e.value = v),
            items: i.value
          }, null, 8, ["modelValue", "items"])
        ]),
        g("div", null, [
          (m(), I(lt((l = i.value.find((v) => v.value === e.value)) == null ? void 0 : l.component), {
            "item-id": n.itemId,
            menu: n.menu
          }, null, 8, ["item-id", "menu"]))
        ])
      ]);
    };
  }
}), Cl = { class: "space-y-24" }, kl = { key: 0 }, wl = /* @__PURE__ */ N({
  __name: "ProductOverview",
  props: {
    itemId: {},
    showSearch: { type: Boolean, default: !1 }
  },
  setup(C) {
    const e = C, i = Fe(), n = F(null);
    return at(() => {
      n.value = e.itemId;
    }), (t, u) => (m(), k("div", Cl, [
      t.showSearch ? (m(), k("div", kl, [
        d(Xt, {
          modelValue: n.value,
          "onUpdate:modelValue": u[0] || (u[0] = (l) => n.value = l),
          class: "w-1/2",
          label: "Search and compare prices",
          "helper-text": "Quickly find products and view their prices across different catalogs and schedules.",
          menu: a(i).state.menu
        }, null, 8, ["modelValue", "menu"])
      ])) : M("", !0),
      g("div", null, [
        n.value ? (m(), I(xl, {
          key: 0,
          "item-id": n.value,
          menu: a(i).state.menu
        }, null, 8, ["item-id", "menu"])) : M("", !0)
      ])
    ]));
  }
}), Sl = /* @__PURE__ */ N({
  __name: "OverviewSheet",
  setup(C) {
    const e = F(null), i = F(!1);
    function n(t) {
      i.value = !i.value, t && (e.value = t);
    }
    return (t, u) => {
      const l = O("FmSideSheet");
      return m(), k(pe, null, [
        _e(t.$slots, "default", { trigger: n }),
        d(l, {
          id: "product-overview",
          modelValue: i.value,
          "onUpdate:modelValue": u[0] || (u[0] = (v) => i.value = v),
          "max-width": 1200,
          "dismiss-away": ""
        }, {
          "side-sheet-header": T(() => u[1] || (u[1] = [
            g("p", { class: "fm-typo-en-title-md-600" }, "Product Overview", -1)
          ])),
          default: T(() => [
            g("div", null, [
              i.value && e.value ? (m(), I(wl, {
                key: 0,
                "item-id": e.value
              }, null, 8, ["item-id"])) : M("", !0)
            ])
          ]),
          _: 1
        }, 8, ["modelValue"])
      ], 64);
    };
  }
});
var Vl = Mt();
const Ye = /* @__PURE__ */ N({
  __name: "ImportButton",
  setup(C) {
    const e = F(!1);
    function i() {
      e.value = !e.value;
    }
    const n = ze();
    return at(() => {
      const t = n.currentCountry.value;
      if (t)
        try {
          Vl.setCountryConfig(t);
        } catch (u) {
          console.log("Unable to set country config", u);
        }
    }), (t, u) => (m(), k(pe, null, [
      d(Ut, {
        modelValue: e.value,
        "onUpdate:modelValue": u[0] || (u[0] = (l) => e.value = l)
      }, null, 8, ["modelValue"]),
      _e(t.$slots, "default", { trigger: i })
    ], 64));
  }
}), Je = (C) => d("div", {
  class: "flex flex-1 justify-end"
}, [d("span", null, [C, et(" ")])]), Fl = {
  class: "flex justify-between items-center space-x-8"
}, Il = {
  class: "flex space-x-8 items-center"
}, $l = {
  class: "w-[320px]"
}, Tl = {
  key: 0
}, Pl = {
  key: 1,
  class: /* @__PURE__ */ ve(["flex-1 flex flex-col", "divide-y divide-fm-color-neutral-gray-100", "overflow-hidden"])
}, Al = {
  key: 0,
  class: "flex items-center p-4"
}, Rl = {
  class: /* @__PURE__ */ ve(["mr-8", "fm-typo-en-body-md-400"])
}, Ml = {
  key: 1,
  class: "px-16 py-4 space-x-8 flex justify-end"
}, Ul = {
  key: 2
}, zl = {
  class: "flex space-x-8"
}, Dl = {
  key: 1,
  class: "pt-8 flex flex-col flex-1 overflow-hidden"
}, Ol = {
  class: "space-y-8 pb-8"
}, Bl = {
  class: "w-full px-8"
}, Kl = {
  class: "flex space-x-8 px-8"
}, Nl = {
  key: 0,
  class: "px-8"
}, jl = {
  key: 0,
  class: /* @__PURE__ */ ve(["flex flex-col flex-1", "overflow-scroll", "divide-y divide-fm-color-neutral-gray-100", "pb-64"])
}, El = ["onClick"], Gl = {
  class: "min-w-0 flex flex-1 items-center justify-start space-x-16"
}, Ll = {
  class: "flex-1 min-w-0"
}, ql = {
  class: "flex justify-between items-center gap-8 pb-4"
}, Wl = {
  class: "flex-1 min-w-0 fm-typo-en-body-lg-600 line-clamp-2"
}, Hl = {
  class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
}, Ql = {
  class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
}, Yl = {
  class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
}, Jl = {
  key: 1
}, Zl = {
  class: "flex space-x-8"
}, Xl = /* @__PURE__ */ N({
  __name: "ProductTable",
  props: {
    modelValue: {},
    originalValue: {},
    isCalculating: {
      type: Boolean
    }
  },
  emits: ["update:model-value", "reset:model-value", "update:editing", "update:search-key"],
  setup(C, {
    expose: e,
    emit: i
  }) {
    const n = C, {
      t
    } = Ie(), u = ze(), l = Fe(), v = Tt(), f = ot(), s = u.currentCountry, b = h(() => s.value ? me.Country.getCountry(s.value) : null), y = h(() => l.rules.item), {
      selectedCategories: w
    } = Se(), z = h(() => {
      const o = ge.flatten(w.value.map((r) => r.items));
      return ge.uniqBy(o, (r) => r._id);
    }), Y = i, S = F(!1);
    de(() => S.value, (o) => {
      Y("update:editing", o);
    });
    const oe = (o) => {
      zt.isBoolean(o) ? S.value = o : S.value = !S.value;
    }, J = F(!1), re = F(null);
    async function G() {
      J.value = !J.value, J.value && (await Ae(), re.value && re.value.toggleProperty(!0));
    }
    e({
      toggleAttributeFilter: G
    });
    const {
      attributes: B,
      filterRule: D,
      mongoQuery: H
    } = xt({
      valueSource: z,
      entity: "item"
    }), Z = F(""), ne = Ct(Z, 300), Q = h(() => {
      const o = (c) => {
        var x;
        return !ne.value || !ne.value.trim() ? !0 : [c.code, c.name, Be(c), ...Pe(se.value, c), (x = Ce()[c.orderFrom]) == null ? void 0 : x.label, Object.values(c.customAttributes ?? {}).join(" ")].join(" ").toLowerCase().includes(ne.value.toLowerCase());
      }, r = (c) => H.value ? $t(c.customAttributes, H.value) : !0;
      return z.value.filter((c) => o(c) && r(c));
    }), {
      categories: se
    } = Se(), R = h(() => l.categories.map((o) => ({
      label: o.name,
      value: o._id || null
    }))), $ = (o, r, c) => {
      let p = ge.clone(n.modelValue);
      const x = p[o];
      x && (typeof r == "object" && r !== null ? p[o] = {
        ...x,
        ...r
      } : p[o] = {
        ...x,
        [r]: c
      }, Y("update:model-value", p));
    }, P = bt(() => n.originalValue, () => n.modelValue), A = ge.debounce($, 300), ue = (o) => (r) => !!r || t("menu.product.table.validation.name_required", {
      field: o
    }), L = (o) => o >= 0 || t("menu.product.table.validation.price_min"), j = [ue("Name")], U = () => [(o) => L(typeof o == "number" ? o : Number(o) ?? 0)], ie = Ce(), E = h(() => {
      const o = l.isV4;
      return gt.setCoreStore(u).taxSetting(o);
    }), ce = h(() => [{
      accessorKey: "thumbnail",
      header: "",
      size: 110,
      meta: {
        cellClass: "px-0",
        headerContentClass: "px-0"
      },
      cell: (o) => {
        var r, c;
        return q(Ue, {
          src: o.getValue(),
          alt: (c = (r = o == null ? void 0 : o.row) == null ? void 0 : r.original) == null ? void 0 : c.name,
          className: "my-8 mx-12",
          size: 72,
          crossorigin: !1
        });
      },
      enableSorting: !1
    }, {
      accessorKey: "code",
      header: () => t("menu.product.table.columns.code"),
      enableSorting: !1,
      size: 100,
      cell: (o) => {
        const r = o.row.original, c = o.getValue() || "--";
        if (!S.value) return d("span", {
          class: "break-all"
        }, [c]);
        const p = Te(r._id);
        return q(te.FmTextField, {
          disabled: !y.value.code,
          modelValue: P(r._id, "code") ?? (p == null ? void 0 : p.code),
          placeholder: n.modelValue[r._id].fallbackCode,
          "onUpdate:modelValue": (x) => {
            A(r._id, "code", x);
          }
        });
      }
    }, {
      accessorKey: "name",
      header: () => t("menu.product.table.columns.name"),
      enableSorting: !1,
      size: 200,
      cell: (o) => {
        const r = o.row.original, c = o.getValue();
        return S.value ? q(te.FmTextField, {
          disabled: !y.value.name,
          modelValue: P(r._id, "name") ?? r.name,
          "onUpdate:modelValue": (p) => {
            A(r._id, "name", p);
          },
          rules: j,
          placeholder: r.fallbackName
        }) : c;
      }
    }, {
      accessorKey: "price",
      header: () => {
        var o;
        return Je(t("menu.product.table.columns.price", {
          currency: (o = b.value) == null ? void 0 : o.currency.symbol
        }));
      },
      enableSorting: !1,
      size: 140,
      meta: {
        textAlign: "right"
      },
      cell: (o) => {
        var x;
        const r = o.getValue();
        if (!S.value) return me.Dinero.fromFdoDinero(r).toFormat();
        const c = n.modelValue[o.row.original._id], p = c.fallbackPrice;
        return q(Rt, {
          min: 0,
          disabled: !c.editPrice,
          // @ts-ignore
          placeholder: p ? Dt(p, !1) : void 0,
          modelValue: P(c._id, "price") ?? ((x = Te(c._id)) == null ? void 0 : x.price),
          // @ts-ignore
          "onUpdate:modelValue": (V) => {
            $(c._id, "price", V);
          },
          rules: U()
        });
      }
    }, {
      accessorKey: "taxes",
      header: () => Je(E.value.systemCode),
      size: S.value ? 120 : 80,
      enableSorting: !1,
      meta: {
        textAlign: "right"
      },
      cell: (o) => {
        const r = o.getValue(), c = o.row.original, p = l.taxSetting.countryTaxOptions, x = l.getSelectedTax(r, c.fallbackTaxes, l.taxSetting.countryTaxOptions), V = p.find((ae) => ae.value === x);
        if (!S.value)
          return `${V != null && V.meta.rate ? _t(V.meta.rate) : 0}%`;
        const _ = l.getSelectedTax(P(c._id, "taxes") ?? r, c.fallbackTaxes, l.taxSetting.countryTaxOptions);
        return q(te.FmSelect, {
          disabled: !y.value.tax,
          items: l.taxSetting.countryTaxOptions,
          modelValue: _,
          "onUpdate:modelValue": async (ae) => {
            const xe = l.decodeTax(ae);
            A(c._id, "taxes", [xe]);
          }
        });
      }
    }, {
      accessorKey: "category",
      header: () => t("menu.product.table.columns.category"),
      enableSorting: !1,
      size: 140,
      cell: (o) => {
        const r = o.row.original;
        if (!S.value)
          return q(Qe, {
            categories: Pe(se.value, r)
          });
        const c = yt(n.originalValue, n.modelValue, r._id) ?? ht(r), p = (c == null ? void 0 : c.map((V) => V._id)) ?? [], x = c == null ? void 0 : c.reduce((V, _) => (V[_._id] = _, V), {});
        return q(It, {
          shouldShowChips: !1,
          shouldShowSelectedItemsWithinPlaceholder: !0,
          modelValue: p.length > 0 ? p : [null],
          items: R.value,
          disabled: !!(l.state.currentCatalogId || l.state.currentSchedulerId),
          "onUpdate:modelValue": async (V) => {
            const [_, ...ae] = V;
            A(r._id, {
              category: _,
              additionalCategories: ae.map((xe) => {
                const Ne = x == null ? void 0 : x[xe];
                return Ne || {
                  _id: xe,
                  position: null
                };
              })
            });
          }
        });
      }
    }, {
      id: "tagging",
      accessorKey: "tagging",
      header: () => t("menu.product.table.columns.tagging"),
      enableSorting: !1,
      size: 140,
      cell: (o) => {
        const r = o.row.original;
        return q(Me, {
          customAttributes: r.customAttributes
        });
      }
    }, {
      accessorKey: "orderFrom",
      header: () => t("menu.product.table.columns.order_from"),
      enableSorting: !0,
      sortingFn: (o, r) => {
        const [c, p] = [o, r].map((x) => ie[x.original.orderFrom].sortingIndex);
        return c - p;
      },
      size: 140,
      cell: (o) => {
        const r = o.getValue(), c = o.row.original;
        return S.value ? q(te.FmSelect, {
          disabled: !y.value.orderFrom,
          items: Object.values(Ce()),
          modelValue: P(c._id, "orderFrom") ?? r,
          "onUpdate:modelValue": async (p) => {
            $(c._id, "orderFrom", p);
          }
        }) : q(Ve, {
          orderFrom: r
        });
      }
    }, {
      id: "actions",
      size: 100,
      meta: {
        cellClass: "pl-16",
        headerClass: "py-4",
        textAlign: "right"
      },
      header: () => q("div", {
        class: "w-full px-4 flex justify-end"
      }, [Ot(q(te.FmButton, {
        variant: ee.Tertiary,
        textColor: W.NeutralGray400,
        prependIcon: "edit",
        class: "flex justify-end",
        onClick: oe,
        type: "button"
      }), "Bulk edit")]),
      cell: (o) => {
        const r = o.row.original;
        return d("div", {
          class: "px-4 flex justify-end"
        }, [d(Sl, null, {
          default: ({
            trigger: c
          }) => d(te.FmButton, {
            icon: "overview",
            variant: "tertiary",
            textColor: W.NeutralGray400,
            onClick: fe(() => {
              c(r._id);
            }, ["stop", "prevent"])
          }, null)
        }), d(te.FmButton, {
          icon: "delete",
          variant: "tertiary",
          textColor: W.NeutralGray400,
          onClick: fe(async () => {
            await f.deleteItem([{
              _id: r._id,
              name: r.name,
              thumbnail: r.thumbnail
            }]);
          }, ["stop", "prevent"])
        }, null)]);
      }
    }]);
    l.taxSetting.systemCode || ce.value.splice(4, 1);
    const le = F({}), X = F([]);
    de([() => le.value, () => Q.value], (o) => {
      let r = [];
      Object.keys(o[0]).forEach((c) => {
        const p = o[0][c], x = Q.value[parseInt(c)];
        x && (p ? r.push(x) : X.value = r.filter((V) => V !== x));
      }), X.value = r;
    }), de(() => z.value, () => {
      le.value = {}, X.value = [];
    }), de(() => S.value, () => {
      le.value = {}, X.value = [];
    });
    const ye = () => {
      le.value = {};
    };
    async function Oe() {
      await Ae();
      const o = () => !!l.currentCatalog || !!l.state.currentSchedulerId, r = (p) => p === "" || p === null ? o() ? "" : null : p, c = Object.values(n.modelValue).filter((p) => {
        const x = Object.values(n.originalValue).find((V) => V._id === p._id);
        return Ee(x, p);
      }).map((p) => ({
        _id: p._id,
        name: p.name,
        code: p.code,
        price: p.price,
        orderFrom: p.orderFrom ?? null,
        taxes: p.taxes,
        category: r(p.category || null),
        additionalCategories: p.additionalCategories
      }));
      await f.updateMany(c), oe(!1);
    }
    const st = async () => {
      await f.deleteItem(X.value.map((o) => ({
        _id: o._id,
        name: o.name,
        thumbnail: o.thumbnail
      })));
    }, he = () => {
      Y("reset:model-value");
    }, $e = () => {
      Object.entries(n.modelValue).some(([r, c]) => Ee(c, n.originalValue[r])) ? v.open({
        title: "You have unsaved changes!",
        message: "Are you sure you want to discard? You will lose all the changes if discard edit.",
        primaryActions: {
          text: "Discard",
          close: !0,
          variant: ee.Destructive
        },
        secondaryActions: {
          text: "Cancel",
          close: !0
        }
      }).onPrimary(() => {
        he(), oe(!1);
      }) : (oe(!1), he());
    }, ut = h(() => {
      var o, r;
      return {
        thumbnail: !S.value,
        actions: !S.value,
        tagging: !S.value && ((r = (o = u.itemAttributeSettings) == null ? void 0 : o.value) == null ? void 0 : r.length) > 0
      };
    }), it = (o) => {
      f.update(o._id);
    };
    async function ct(o) {
      await f.update(o.original._id);
    }
    function Be(o) {
      var _;
      const r = o.price ?? // TODO: fix type error
      // @ts-ignore
      o.fallbackPrice ?? me.Dinero.fromNumber({
        number: 0
      }).toObject(), c = o.taxes, p = l.taxSetting.countryTaxOptions, x = me.Dinero.fromFdoDinero(r).toFormat(), V = (_ = b.value) == null ? void 0 : _.currency.symbol;
      return l.getSelectedTax(
        c,
        // TODO: fix type error
        // @ts-ignore
        o.fallbackTaxes,
        p
      ), `${V == null ? void 0 : V.toUpperCase()}${x}`;
    }
    function Te(o) {
      var p;
      const r = l.currentCatalog, c = l.state.currentSchedulerId;
      if (r && c) {
        const x = r.override.scheduler[c] ?? {}, V = (p = x == null ? void 0 : x.items) == null ? void 0 : p.filter((_) => _._id === o);
        return V == null ? void 0 : V[0];
      } else return r ? r.override.items[o][0] : c ? l.schedulers.find((_) => _._id === c).items.filter((_) => _._id === o)[0] : z.value.find((x) => x._id === o);
    }
    const dt = rt(), mt = h(() => dt.breakpoints.value.xs), Ke = F(null), pt = At(Ke, J), vt = h(() => {
      var r;
      return {
        height: `calc(100vh - ${((r = pt.value) == null ? void 0 : r.top) + 24}px)`
      };
    });
    return (o, r) => {
      const c = O("fm-search"), p = O("fm-button"), x = O("fm-table"), V = O("fm-form");
      return mt.value ? (m(), k("div", Dl, [g("div", Ol, [g("div", Bl, [d(c, {
        "model-value": Z.value,
        "onUpdate:modelValue": r[5] || (r[5] = (_) => Z.value = _),
        autofocus: "",
        placeholder: a(t)("menu.product.table.search.placeholder")
      }, null, 8, ["model-value", "placeholder"])]), r[8] || (r[8] = g("div", {
        class: "w-full h-[1px] bg-fm-color-neutral-gray-100"
      }, null, -1)), g("div", Kl, [_e(o.$slots, "filter")]), J.value ? (m(), k("div", Nl, [d(a(We), {
        ref_key: "attributeFilterRef",
        ref: re,
        attributes: a(B),
        modelValue: a(D),
        "onUpdate:modelValue": r[6] || (r[6] = (_) => je(D) ? D.value = _ : null)
      }, null, 8, ["attributes", "modelValue"])])) : M("", !0)]), z.value.length ? (m(), k("div", jl, [(m(!0), k(pe, null, we(Q.value, (_) => {
        var ae;
        return m(), k("div", {
          key: _._id,
          class: "max-w-full py-12 px-16 space-x-16 flex items-center",
          onClick: () => it(_)
        }, [g("div", Gl, [d(Ue, {
          alt: _.name,
          size: 72,
          src: _.thumbnail
        }, null, 8, ["alt", "src"]), g("div", Ll, [g("div", ql, [g("p", Wl, K(_.name), 1), d(Ve, {
          "order-from": _.orderFrom
        }, null, 8, ["order-from"])]), g("p", Hl, K(Be(_)), 1), g("p", Ql, K(a(t)("menu.product.table.columns.code")) + ": " + K(((ae = Te(_._id)) == null ? void 0 : ae.code) || "--"), 1), g("p", Yl, [d(Qe, {
          categories: a(Pe)(a(se), _)
        }, null, 8, ["categories"])]), d(Me, {
          "custom-attributes": _.customAttributes
        }, null, 8, ["custom-attributes"])])]), d(p, {
          "text-color": a(W).NeutralGray400,
          variant: a(ee).Tertiary,
          "prepend-icon": "delete",
          onClick: fe(() => a(f).deleteItem([{
            _id: _._id,
            name: _.name,
            thumbnail: _.thumbnail
          }]), ["stop"])
        }, null, 8, ["text-color", "variant", "onClick"])], 8, El);
      }), 128))])) : (m(), k("div", Jl, [d(be, {
        subtitle: a(t)("menu.product.table.empty.subtitle"),
        title: a(t)("menu.product.table.empty.title")
      }, {
        action: T(() => [g("div", Zl, [d(p, {
          variant: a(ee).Primary,
          label: a(t)("menu.product.table.empty.actions.add"),
          "prepend-icon": "add",
          onClick: r[7] || (r[7] = (_) => a(f).create(null))
        }, null, 8, ["variant", "label"]), d(Ye, null, {
          default: T(({
            trigger: _
          }) => [d(p, {
            "bg-color": a(W).NeutralGray100,
            "text-color": a(W).NeutralGray400,
            variant: a(ee).Primary,
            label: a(t)("menu.product.table.empty.actions.import"),
            "prepend-icon": "download",
            onClick: _
          }, null, 8, ["bg-color", "text-color", "variant", "label", "onClick"])]),
          _: 1
        })])]),
        _: 1
      }, 8, ["subtitle", "title"])]))])) : (m(), I(V, {
        key: 0,
        "blame-form-child-on-validation-failed": "",
        class: "flex flex-col flex-1 space-y-8 overflow-hidden",
        onValidationSuccess: Oe
      }, {
        default: T(() => [g("div", Fl, [g("div", Il, [_e(o.$slots, "filter")]), g("div", $l, [d(c, {
          "model-value": Z.value,
          "onUpdate:modelValue": r[0] || (r[0] = (_) => Z.value = _),
          autofocus: "",
          placeholder: a(t)("menu.product.table.search.placeholder")
        }, null, 8, ["model-value", "placeholder"])])]), J.value ? (m(), k("div", Tl, [d(a(We), {
          ref_key: "attributeFilterRef",
          ref: re,
          attributes: a(B),
          modelValue: a(D),
          "onUpdate:modelValue": r[1] || (r[1] = (_) => je(D) ? D.value = _ : null)
        }, null, 8, ["attributes", "modelValue"])])) : M("", !0), z.value.length ? (m(), k("div", Pl, [X.value.length && !S.value ? (m(), k("div", Al, [g("p", Rl, K(a(t)("menu.product.table.selection.count", {
          count: X.value.length
        })), 1), d(p, {
          label: a(t)("menu.product.table.selection.actions.deselect_all"),
          type: "button",
          variant: "plain",
          onClick: ye
        }, null, 8, ["label"]), d(p, {
          "border-color": a(W).SystemError300,
          "text-color": a(W).SystemError300,
          class: "ml-auto",
          label: a(t)("menu.product.table.selection.actions.remove"),
          "prepend-icon": "delete",
          variant: "secondary",
          onClick: st
        }, null, 8, ["border-color", "text-color", "label"])])) : M("", !0), S.value ? (m(), k("div", Ml, [d(p, {
          variant: a(ee).Tertiary,
          label: a(t)("menu.product.table.bulk_edit.actions.reset_all"),
          onClick: he
        }, null, 8, ["variant", "label"]), d(p, {
          variant: a(ee).Tertiary,
          label: a(t)("menu.common.actions.cancel"),
          onClick: $e
        }, null, 8, ["variant", "label"]), d(p, {
          borderColor: a(W).ColorPrimary,
          textColor: a(W).ColorPrimary,
          variant: a(ee).Secondary,
          label: a(t)("menu.product.table.bulk_edit.actions.save"),
          type: "submit"
        }, null, 8, ["borderColor", "textColor", "variant", "label"])])) : M("", !0), g("div", {
          ref_key: "tableWrapper",
          ref: Ke
        }, [(m(), I(lt(S.value ? Pt : "div"), {
          ref: "fullWrapper",
          title: S.value ? a(t)("menu.product.table.bulk_edit.title") : "",
          show: S.value,
          "primary-action": {
            label: a(t)("menu.product.table.bulk_edit.actions.save")
          },
          "secondary-actions": [{
            label: a(t)("menu.product.table.bulk_edit.actions.reset_all"),
            click: he
          }, {
            label: a(t)("menu.common.actions.cancel"),
            click: $e
          }],
          class: "overflow-x-scroll",
          style: ft(vt.value),
          onOnPrimary: Oe,
          onOnCancel: $e
        }, {
          default: T(() => [d(x, {
            class: ve({
              "min-w-[1100px]": !0,
              "mt-24": S.value
            }),
            modelValue: le.value,
            "onUpdate:modelValue": r[2] || (r[2] = (_) => le.value = _),
            "column-defs": ce.value,
            "column-visibility": ut.value,
            loading: o.isCalculating,
            "page-size": Q.value.length,
            "row-data": Q.value,
            "shrink-at": !1,
            selection: S.value ? void 0 : "multiple",
            virtual: !0,
            "virtual-row-height": S.value ? 48 : 91,
            "hide-footer": "",
            "pin-header-row": "",
            onRowClick: r[3] || (r[3] = (_) => S.value ? void 0 : ct(_))
          }, null, 8, ["class", "modelValue", "column-defs", "column-visibility", "loading", "page-size", "row-data", "selection", "virtual-row-height"])]),
          _: 1
        }, 40, ["title", "show", "primary-action", "secondary-actions", "style"]))], 512)])) : (m(), k("div", Ul, [d(be, {
          subtitle: a(t)("menu.product.table.empty.subtitle"),
          title: a(t)("menu.product.table.empty.title")
        }, {
          action: T(() => [g("div", zl, [d(p, {
            variant: a(ee).Primary,
            label: a(t)("menu.product.table.empty.actions.add"),
            "prepend-icon": "add",
            onClick: r[4] || (r[4] = (_) => a(f).create(null))
          }, null, 8, ["variant", "label"]), d(Ye, null, {
            default: T(({
              trigger: _
            }) => [d(p, {
              "bg-color": a(W).NeutralGray100,
              "text-color": a(W).NeutralGray400,
              variant: a(ee).Primary,
              label: a(t)("menu.product.table.empty.actions.import"),
              "prepend-icon": "download",
              onClick: _
            }, null, 8, ["bg-color", "text-color", "variant", "label", "onClick"])]),
            _: 1
          })])]),
          _: 1
        }, 8, ["subtitle", "title"])]))]),
        _: 3
      }));
    };
  }
}), ea = {
  key: 0,
  class: /* @__PURE__ */ ve(["flex flex-col", "flex-1", "overflow-hidden"])
}, ta = {
  class: /* @__PURE__ */ ve(["pt-16 xs:pt-0", "flex xs:flex-col", "flex-1", "w-full", "overflow-hidden"])
}, la = { class: "flex flex-col flex-1 overflow-hidden" }, aa = {
  key: 1,
  class: "pt-16 xs:pt-8 space-y-24"
}, oa = { class: "flex items-center gap-8 px-16" }, Sa = /* @__PURE__ */ N({
  __name: "Product",
  setup(C) {
    const e = Fe(), i = h(() => e.rules.item), n = ot(), t = h(() => !e.state.currentCatalogId), u = h(() => e.rules.item), l = h(() => !e.state.currentSchedulerId), v = F(!1), f = F(!1), s = h(() => {
      var $, P, A, ue;
      if (t.value && l.value) return;
      if (l.value) {
        const L = ($ = e.currentCatalog) == null ? void 0 : $.override.items;
        return L ? Object.entries(L).reduce((j, [U, ie]) => {
          const E = ie.find((ce) => !ce.combinationKey);
          return E && (j[U] = E), j;
        }, {}) : {};
      }
      return ((t.value ? (P = e.currentScheduler) == null ? void 0 : P.items : (ue = (A = e.currentCatalog) == null ? void 0 : A.override.scheduler[e.state.currentSchedulerId]) == null ? void 0 : ue.items) ?? []).reduce((L, j) => (j.combinationKey || (L[j._id] = j), L), {});
    }), b = F({}), y = F({}), w = async () => {
      var ue, L;
      f.value = !0;
      const R = !!s.value, $ = ge.flatten(Y.value.map((j) => j.items)), P = R && v.value ? await Ft(
        e.mergedMenu,
        $,
        e.state.menu,
        (ue = e.currentCatalog) == null ? void 0 : ue._id,
        (L = e.currentScheduler) == null ? void 0 : L._id,
        !1
      ) : void 0, A = $.reduce((j, U, ie) => {
        var ce, le, X, ye;
        const E = (ce = s.value) == null ? void 0 : ce[U._id];
        return j[U._id] = {
          _id: U._id,
          name: U.name,
          code: R ? E == null ? void 0 : E.code : U == null ? void 0 : U.code,
          category: U.category,
          additionalCategories: U.additionalCategories,
          price: R && u.value.editPrice ? E == null ? void 0 : E.price : U.price,
          orderFrom: R ? E == null ? void 0 : E.orderFrom : U.orderFrom,
          taxes: R ? null : U.taxes,
          thumbnail: U.thumbnail,
          fallbackPrice: (le = P == null ? void 0 : P[ie]) == null ? void 0 : le.price,
          fallbackName: R ? U.name : void 0,
          fallbackCode: (X = P == null ? void 0 : P[ie]) == null ? void 0 : X.code,
          fallbackOrder: (ye = P == null ? void 0 : P[ie]) == null ? void 0 : ye.orderFrom,
          fallbackTaxes: R ? U.taxes : null
        }, j;
      }, {});
      b.value = A, y.value = { ...A }, f.value = !1;
    }, { categories: z, selectedCategories: Y } = Se(), S = F(null);
    function oe() {
      S.value && S.value.toggleAttributeFilter();
    }
    tt(async () => {
      Y.value && await w();
    });
    function J() {
      n.create(null);
    }
    const re = () => {
      Y.value && w();
    }, { t: G } = Ie(), B = h(() => {
      var R, $;
      return ($ = (R = e.currentCatalog) == null ? void 0 : R.linkItemRules) == null ? void 0 : $.length;
    }), {
      menuItems: D,
      categories: H,
      linkItemRules: Z,
      handleSubmit: ne,
      catalogManager: Q,
      schedulerManager: se
    } = kt(!1);
    return (R, $) => {
      const P = O("fm-button");
      return a(z).length ? (m(), k("div", ea, [
        g("div", ta, [
          g("div", la, [
            a(Y) ? (m(), I(Xl, {
              key: 0,
              ref_key: "productTableRef",
              ref: S,
              "is-calculating": f.value,
              "model-value": b.value,
              "original-value": y.value,
              "onUpdate:modelValue": $[1] || ($[1] = (A) => b.value = A),
              "onReset:modelValue": re,
              "onUpdate:editing": $[2] || ($[2] = (A) => v.value = A)
            }, {
              filter: T(() => [
                d(He, { onToggleAttributeFilter: oe }),
                u.value.multiScheduler ? (m(), I(qe, { key: 0 })) : M("", !0),
                B.value ? (m(), I(Le, {
                  key: 1,
                  "current-restaurant-attr-params": a(e).state.currentRestaurantAttrParams,
                  onConfirm: $[0] || ($[0] = (A) => a(e).setRestaurantAttrParams(A))
                }, null, 8, ["current-restaurant-attr-params"])) : M("", !0)
              ]),
              _: 1
            }, 8, ["is-calculating", "model-value", "original-value"])) : M("", !0)
          ])
        ])
      ])) : (m(), k("div", aa, [
        g("div", oa, [
          d(He),
          u.value.multiScheduler ? (m(), I(qe, { key: 0 })) : M("", !0),
          B.value ? (m(), I(Le, {
            key: 1,
            "current-restaurant-attr-params": a(e).state.currentRestaurantAttrParams,
            onConfirm: $[3] || ($[3] = (A) => a(e).setRestaurantAttrParams(A))
          }, null, 8, ["current-restaurant-attr-params"])) : M("", !0)
        ]),
        i.value.create ? (m(), I(be, {
          key: 0,
          action: {
            text: a(G)("menu.product.empty.with_create.action"),
            callback: J
          },
          subtitle: a(G)("menu.product.empty.with_create.subtitle"),
          title: a(G)("menu.product.empty.with_create.title")
        }, null, 8, ["action", "subtitle", "title"])) : l.value ? (m(), I(be, {
          key: 1,
          subtitle: a(G)("menu.product.empty.no_scheduler.subtitle"),
          title: a(G)("menu.product.empty.no_scheduler.title")
        }, {
          action: T(() => [
            d(Ge, {
              "categorized-items": a(Q).linkableItems.value,
              "initial-value": a(Q).currentItems.value,
              "show-variant": !1,
              "menu-items": a(D),
              categories: a(H),
              "link-item-rules": a(Z),
              "no-scheduler": l.value,
              "is-local-only": !0,
              onSubmit: a(ne)
            }, {
              default: T(({ trigger: A }) => [
                d(P, {
                  label: a(G)("menu.common.actions.link_product"),
                  "prepend-icon": "link",
                  onClick: A
                }, null, 8, ["label", "onClick"])
              ]),
              _: 1
            }, 8, ["categorized-items", "initial-value", "menu-items", "categories", "link-item-rules", "no-scheduler", "onSubmit"])
          ]),
          _: 1
        }, 8, ["subtitle", "title"])) : (m(), I(be, {
          key: 2,
          subtitle: a(G)("menu.product.empty.with_scheduler.subtitle"),
          title: a(G)("menu.product.empty.with_scheduler.title")
        }, {
          action: T(() => [
            d(Ge, {
              "categorized-items": a(se).linkableItems.value,
              "initial-value": a(se).currentItems.value,
              "show-variant": !1,
              "menu-items": a(D),
              categories: a(H),
              "link-item-rules": a(Z),
              "no-scheduler": l.value,
              "is-local-only": !0,
              onSubmit: a(ne)
            }, {
              default: T(({ trigger: A }) => [
                d(P, {
                  label: a(G)("menu.common.actions.apply_product"),
                  onClick: A
                }, null, 8, ["label", "onClick"])
              ]),
              _: 1
            }, 8, ["categorized-items", "initial-value", "menu-items", "categories", "link-item-rules", "no-scheduler", "onSubmit"])
          ]),
          _: 1
        }, 8, ["subtitle", "title"]))
      ]));
    };
  }
});
export {
  Ye as _,
  Sa as a
};
