import { defineComponent as E, computed as g, ref as j, resolveComponent as M, createBlock as y, openBlock as m, unref as e, withCtx as c, createElementVNode as i, toDisplayString as q, createVNode as o, createCommentVNode as G, createElementBlock as A, Fragment as P } from "vue";
import { D as F } from "./dayjs.min-4uUKJ0sS.js";
import { J as oe, F as ne } from "./jszip.min-JM2t-R2Y.js";
import { u as J, G as W, B as R, H, A as Z, D as ae, I as re, J as U, K as se } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
import { w as ie } from "./ImportProductDialog.vue_vue_type_script_setup_true_lang-loNz40wt.js";
import { useCoreStore as K, useI18n as le } from "@feedmepos/mf-common";
import { useDialog as Q, useDialogChild as ue, useSnackbar as X, useBreakpoints as ce, FmButtonVariant as $, FmButtonColorThemeVariant as h } from "@feedmepos/ui-library";
import { _ as V } from "./ResponsiveFabButton.vue_vue_type_script_setup_true_lang-Cn-3MRBO.js";
import { _ as me, a as z } from "./BottomSheetMenuItem.vue_vue_type_script_setup_true_lang-DhrXKy3b.js";
import { _ as de } from "./PageLayout.vue_vue_type_script_setup_true_lang-2f0QfweQ.js";
import { u as pe, a as fe } from "./menu-DNLXOwiM.js";
import { u as _e } from "./item-BZS28ZS_.js";
import { _ as L, a as ve } from "./Product.vue_vue_type_script_setup_true_lang-C8rOVEcT.js";
import { L as O } from "./LinkProductSideSheet-DUHaljek.js";
import { _ as ge } from "./TreeEditorOpenner.vue_vue_type_script_setup_true_lang-DNP5g4bj.js";
import { u as be } from "./Thumbnail.vue_vue_type_script_setup_true_lang-ChJOXWkd.js";
import { m as ye } from "./toExcel-BjgkWZco.js";
const ke = { class: "space-y-24 mb-24" }, xe = ["innerHTML"], he = { class: "flex justify-end gap-8" }, Se = /* @__PURE__ */ E({
  __name: "ConfirmActionDialog",
  props: {
    description: {},
    value: {},
    message: { default: "To confirm your action, type <b>[[value]]</b> in the text field." }
  },
  setup(C) {
    const t = C, S = g(() => t.message.replace("[[value]]", t.value)), k = j(""), r = Q(), { emitAction: x } = ue();
    return (d, s) => {
      const p = M("FmTextField"), f = M("FmButton"), _ = M("FmForm");
      return m(), y(_, {
        "on-validation-success": () => e(x)("primary"),
        "blame-form-child-on-validation-failed": ""
      }, {
        default: c(() => [
          i("div", ke, [
            i("div", null, q(d.description), 1),
            i("div", { innerHTML: S.value }, null, 8, xe),
            i("div", null, [
              o(p, {
                modelValue: k.value,
                "onUpdate:modelValue": [
                  s[0] || (s[0] = (l) => k.value = l),
                  s[1] || (s[1] = () => {
                  })
                ],
                placeholder: d.value,
                rules: [(l) => l === d.value || "Value does not match"]
              }, null, 8, ["modelValue", "placeholder", "rules"])
            ]),
            i("div", he, [
              o(f, {
                label: "Cancel",
                variant: "secondary",
                onClick: s[2] || (s[2] = (l) => e(r).close())
              }),
              o(f, {
                label: "Confirm",
                type: "submit"
              })
            ])
          ])
        ]),
        _: 1
      }, 8, ["on-validation-success"]);
    };
  }
}), Me = /* @__PURE__ */ E({
  __name: "Migrate",
  setup(C) {
    const t = J(), S = K(), k = X(), { minor: r } = W(k), x = j(!1), d = Q();
    async function s() {
      p.value || x.value || d.open({
        title: "Migrate to new version",
        contentComponent: Se,
        contentComponentProps: {
          value: "MIGRATE",
          description: "Do you want to migrate to new version? Once migrate it will unable to revert to the older version."
        }
      }).onPrimary(async () => {
        d.close(), await r(
          async () => {
            await t.migrate(), setTimeout(() => {
              window.location.reload();
            }, 2e3);
          },
          {
            isLoading: x,
            customId: t.state.menu._id,
            message: "Migrating menu",
            successMessage: "Migration completed"
          }
        );
      });
    }
    const p = g(() => {
      const f = S.restaurants.value;
      if (!f.length) return "Required at least one restaurant to migrate";
      const _ = f.filter((b) => !b.posVersion || !R.Pos.canUse({ feature: H.F_FEATURE.enum.menuV4, posVersion: b.posVersion }));
      return _.length ? `Upgrade POS to V${R.Pos.minVersionToUse(H.F_FEATURE.enum.menuV4)} to use new menu: ${_.map((b) => b.profile.name).join(", ")}` : null;
    });
    return g(() => p.value ? p.value : "Migrate your menu to new version to enjoy more features. Content of new menu will remain the same as current."), (f, _) => {
      const l = M("FmSnackbar");
      return !p.value && e(t).version !== e(Z.F_MENU_VERSION).enum.v4 ? (m(), y(l, {
        key: 0,
        class: "!max-w-full",
        title: "New version of menu is out now!",
        description: "Migrate your current menu version to the latest to enjoy more features such as product sequential dispatch, serving sequence, scheduler and more! Your content and current setting will be preserved.",
        variant: "info",
        action: "Migrate",
        "z-index": 0,
        onOnAction: s
      })) : G("", !0);
    };
  }
}), we = "/assets/menu-export-Bs3oJ1b1.js", Ce = { class: "flex-1 flex justify-between gap-8 pl-8" }, Fe = { class: "flex items-center" }, $e = { class: "bg-fm-color-neutral-gray-100 rounded-md px-8 py-4" }, Ve = { class: "fm-typo-en-body-md-600 font-semibold" }, Ee = { class: "flex gap-8" }, Je = /* @__PURE__ */ E({
  __name: "Products",
  setup(C) {
    const { t } = le(), S = K(), k = W(X()), r = J(), x = g(() => r.rules.item), d = _e(), s = g(() => !r.state.currentSchedulerId), { selectedCategories: p } = pe(), f = g(() => ({
      ...ae.menuV4ToV3(re(r.state.menu)),
      _id: r.state.menu._id,
      _rev: r.state.menu._rev
    })), _ = g(() => {
      const u = U.flatten(p.value.map((n) => n.items));
      return U.uniqBy(u, (n) => n._id).length;
    });
    async function l(u, n) {
      const v = new oe();
      for (let w = 0; w < u.length; w++)
        v.file(`${n[w]}.xlsx`, u[w]);
      const a = await v.generateAsync({ type: "blob" });
      ne.saveAs(a, `books_${F().format("DD-MM-YYYY_HH-mm")}.zip`);
    }
    async function b() {
      await k.minor(
        async () => {
          if (await r.readMenu(), r.version === Z.F_MENU_VERSION.enum.v4) {
            const u = r.state.menu, n = F().format("DD-MM-YYYY_HH-mm"), v = [
              `menu_${n}`,
              `addonGroup_${n}`,
              `itemLinkedAddon_${n}`
            ], a = await se(
              we,
              JSON.stringify({
                menu: u,
                attributeSettings: S.itemAttributeSettings.value
              })
            );
            await l(a, v);
          } else {
            const u = ye(f.value), n = `menu_${F().format("DD-MM-YYYY_HH-mm")}`;
            await ie(u, `${n}.xlsx`, {
              bookType: "xlsx",
              bookSST: !0,
              type: "array",
              compression: !0
            });
          }
        },
        { successMessage: "Menu exported", customId: r.state.menu._id }
      );
    }
    const {
      menuItems: T,
      categories: I,
      linkItemRules: D,
      handleSubmit: N,
      catalogManager: B,
      schedulerManager: Y
    } = be(!1), ee = ce(), te = g(() => ee.breakpoints.value.xs);
    return fe().resetOnMount(), (u, n) => {
      const v = M("fm-button");
      return m(), y(de, {
        heading: e(t)("menu.products.title")
      }, {
        default: c(() => [
          o(Me),
          o(ve)
        ]),
        "append-heading": c(() => [
          i("div", Ce, [
            i("div", Fe, [
              i("div", $e, [
                i("p", Ve, q(_.value), 1)
              ])
            ]),
            i("div", Ee, [
              te.value ? (m(), y(L, { key: 1 }, {
                default: c(({ trigger: a }) => [
                  o(me, null, {
                    default: c(() => [
                      o(z, {
                        label: e(t)("menu.products.actions.export"),
                        onClick: b
                      }, null, 8, ["label"]),
                      o(z, {
                        label: e(t)("menu.products.actions.import"),
                        onClick: a
                      }, null, 8, ["label", "onClick"])
                    ]),
                    _: 2
                  }, 1024)
                ]),
                _: 1
              })) : (m(), A(P, { key: 0 }, [
                o(ge, null, {
                  default: c(({ trigger: a }) => [
                    o(v, {
                      label: e(t)("menu.tree_editor.title"),
                      "bg-color": e(h).NeutralGray100,
                      "text-color": e(h).TypoSecondary,
                      variant: e($).Primary,
                      onClick: a
                    }, null, 8, ["label", "bg-color", "text-color", "variant", "onClick"])
                  ]),
                  _: 1
                }),
                o(v, {
                  "bg-color": e(h).NeutralGray100,
                  "text-color": e(h).TypoSecondary,
                  variant: e($).Primary,
                  label: e(t)("menu.products.actions.export"),
                  onClick: b
                }, null, 8, ["bg-color", "text-color", "variant", "label"]),
                o(L, null, {
                  default: c(({ trigger: a }) => [
                    o(v, {
                      "bg-color": e(h).NeutralGray100,
                      "text-color": e(h).TypoSecondary,
                      variant: e($).Primary,
                      label: e(t)("menu.products.actions.import"),
                      onClick: a
                    }, null, 8, ["bg-color", "text-color", "variant", "label", "onClick"])
                  ]),
                  _: 1
                })
              ], 64)),
              _.value > 0 ? (m(), A(P, { key: 2 }, [
                x.value.create ? (m(), y(V, {
                  key: 0,
                  label: e(t)("menu.products.actions.add"),
                  "prepend-icon": "add",
                  onClick: n[0] || (n[0] = (a) => e(d).create(null))
                }, null, 8, ["label"])) : s.value ? (m(), y(O, {
                  key: 1,
                  "categorized-items": e(B).linkableItems.value,
                  "initial-value": e(B).currentItems.value,
                  "show-variant": !1,
                  "menu-items": e(T),
                  categories: e(I),
                  "link-item-rules": e(D),
                  "no-scheduler": s.value,
                  onSubmit: e(N)
                }, {
                  default: c(({ trigger: a }) => [
                    o(V, {
                      label: e(t)("menu.products.actions.link"),
                      "prepend-icon": "link",
                      onClick: a
                    }, null, 8, ["label", "onClick"])
                  ]),
                  _: 1
                }, 8, ["categorized-items", "initial-value", "menu-items", "categories", "link-item-rules", "no-scheduler", "onSubmit"])) : (m(), y(O, {
                  key: 2,
                  "categorized-items": e(Y).linkableItems.value,
                  "initial-value": e(Y).currentItems.value,
                  "show-variant": !1,
                  "menu-items": e(T),
                  categories: e(I),
                  "link-item-rules": e(D),
                  "no-scheduler": s.value,
                  onSubmit: e(N)
                }, {
                  default: c(({ trigger: a }) => [
                    o(V, {
                      label: e(t)("menu.products.actions.apply_scheduler"),
                      onClick: a
                    }, null, 8, ["label", "onClick"])
                  ]),
                  _: 1
                }, 8, ["categorized-items", "initial-value", "menu-items", "categories", "link-item-rules", "no-scheduler", "onSubmit"]))
              ], 64)) : G("", !0)
            ])
          ])
        ]),
        _: 1
      }, 8, ["heading"]);
    };
  }
});
export {
  Je as default
};
