import { defineComponent as F, computed as d, ref as p, watch as A, onMounted as H, resolveComponent as m, createElementBlock as K, openBlock as b, Fragment as Q, createVNode as n, withCtx as u, createElementVNode as i, toDisplayString as M, unref as e, createBlock as D } from "vue";
import { D as W } from "./dayjs.min-4uUKJ0sS.js";
import { useRoute as j, useRouter as J } from "vue-router";
import { _ as X, w as Z } from "./ImportProductDialog.vue_vue_type_script_setup_true_lang-loNz40wt.js";
import { G as ee, u as te, D as ae, I as oe, Q as ne } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
import { useI18n as le } from "@feedmepos/mf-common";
import { useSnackbar as se } from "@feedmepos/ui-library";
import { _ as R } from "./ResponsiveFabButton.vue_vue_type_script_setup_true_lang-Cn-3MRBO.js";
import { L as V } from "./LinkProductSideSheet-DUHaljek.js";
import { _ as ue } from "./index-CisutoS9.js";
import { _ as re } from "./PageLayout.vue_vue_type_script_setup_true_lang-2f0QfweQ.js";
import { u as ie } from "./Thumbnail.vue_vue_type_script_setup_true_lang-ChJOXWkd.js";
import { a as me } from "./menu-DNLXOwiM.js";
import { m as ce } from "./toExcel-BjgkWZco.js";
import { _ as de, u as pe, c as _e } from "./scheduler-D3ecaFZK.js";
import { R as r } from "./app-D-J2cjak.js";
const fe = { class: "px-12 py-8" }, ve = { class: "px-12 py-8" }, ge = { class: "flex ml-auto space-x-8" }, be = { class: "flex-1 flex flex-col overflow-hidden" }, Ge = /* @__PURE__ */ F({
  __name: "[id]",
  setup(ke) {
    const E = j(), _ = J(), k = ee(se()), L = ne(k), a = te(), { t: l } = le(), O = d(() => a.categorizedRawMenuItems), f = d(() => !a.state.currentSchedulerId), G = p();
    async function z(o) {
      const t = o._id ? pe(o) : _e(o);
      await L.updateMenu(t, o.name);
    }
    const h = d(() => [
      {
        label: l("menu.catalog.edit.tabs.product"),
        value: r.EDIT_CATALOG_PRODUCT
      },
      {
        label: l("menu.catalog.edit.tabs.category"),
        value: r.EDIT_CATALOG_CATEGORY
      },
      {
        label: l("menu.catalog.edit.tabs.group"),
        value: r.EDIT_CATALOG_GROUP
      },
      {
        label: l("menu.catalog.edit.tabs.takeaway"),
        value: r.EDIT_CATALOG_TAKEAWAY
      },
      {
        label: l("menu.catalog.edit.tabs.setting"),
        value: r.EDIT_CATALOG_SETTING
      }
    ]), c = p(h.value[0].value);
    A(c, (o) => {
      _.replace({
        name: o
      });
    }), H(() => {
      _.currentRoute.value.name !== r.EDIT_CATALOG && (c.value = _.currentRoute.value.name);
    }), A(
      () => a.state.menu._id,
      (o) => {
        const t = E.params.id;
        o && t !== "main" && a.selectCatalog(t);
      }
    );
    const $ = d(() => ({
      ...ae.menuV4ToV3(oe(a.state.menu)),
      _id: a.state.menu._id,
      _rev: a.state.menu._rev
    }));
    async function U() {
      await k.minor(
        async () => {
          await a.readMenu();
          const o = await ce($.value), t = `menu_${W().format("DD-MM-YYYY_HH-mm")}`;
          await Z(o, `${t}.xlsx`, {
            bookType: "xlsx",
            bookSST: !1,
            type: "array"
          });
        },
        { successMessage: "Menu exported", customId: a.state.menu._id }
      );
    }
    const v = p(!1), g = p(!1), {
      menuItems: x,
      categories: S,
      linkItemRules: T,
      handleSubmit: y,
      catalogManager: C,
      schedulerManager: I
    } = ie(!1);
    return me().resetOnUnmount(), (o, t) => {
      var w;
      const Y = m("fm-bottom-sheet"), N = m("fm-button"), P = m("router-link"), q = m("fm-tabs"), B = m("router-view");
      return b(), K(Q, null, [
        n(de, {
          ref_key: "schedulerDialogRef",
          ref: G,
          "categorized-items": O.value,
          onOnComplete: z
        }, null, 8, ["categorized-items"]),
        n(X, {
          modelValue: v.value,
          "onUpdate:modelValue": t[0] || (t[0] = (s) => v.value = s)
        }, null, 8, ["modelValue"]),
        n(Y, {
          modelValue: g.value,
          "onUpdate:modelValue": t[2] || (t[2] = (s) => g.value = s),
          "no-header": ""
        }, {
          default: u(() => [
            i("div", fe, [
              i("p", {
                class: "fm-typo-en-body-md-400",
                onClick: U
              }, M(e(l)("menu.catalog.edit.export")), 1)
            ]),
            i("div", ve, [
              i("p", {
                class: "fm-typo-en-body-md-400",
                onClick: t[1] || (t[1] = () => {
                  v.value = !0, g.value = !1;
                })
              }, M(e(l)("menu.catalog.edit.import")), 1)
            ])
          ]),
          _: 1
        }, 8, ["modelValue"]),
        n(re, {
          heading: ((w = e(a).currentCatalog) == null ? void 0 : w.name) ?? "Main",
          class: "flex flex-col max-h-[calc(100vh-56px)] overflow-hidden"
        }, {
          "prepend-heading": u(() => [
            n(P, {
              to: { name: e(r).CATALOG },
              class: "mr-8",
              title: e(l)("menu.catalog.edit.back")
            }, {
              default: u(() => [
                n(N, {
                  "prepend-icon": "arrow_back",
                  variant: "tertiary"
                })
              ]),
              _: 1
            }, 8, ["to", "title"])
          ]),
          "append-heading": u(() => [
            i("div", ge, [
              f.value ? (b(), D(V, {
                key: 0,
                "categorized-items": e(C).linkableItems.value,
                "initial-value": e(C).currentItems.value,
                "show-variant": !1,
                "menu-items": e(x),
                categories: e(S),
                "link-item-rules": e(T),
                "no-scheduler": f.value,
                onSubmit: e(y)
              }, {
                default: u(({ trigger: s }) => [
                  n(R, {
                    label: e(l)("menu.catalog.edit.link_product"),
                    "prepend-icon": "link",
                    onClick: s
                  }, null, 8, ["label", "onClick"])
                ]),
                _: 1
              }, 8, ["categorized-items", "initial-value", "menu-items", "categories", "link-item-rules", "no-scheduler", "onSubmit"])) : (b(), D(V, {
                key: 1,
                "categorized-items": e(I).linkableItems.value,
                "initial-value": e(I).currentItems.value,
                "show-variant": !1,
                "menu-items": e(x),
                categories: e(S),
                "link-item-rules": e(T),
                "no-scheduler": f.value,
                onSubmit: e(y)
              }, {
                default: u(({ trigger: s }) => [
                  n(R, {
                    label: e(l)("menu.catalog.edit.apply_scheduler"),
                    onClick: s
                  }, null, 8, ["label", "onClick"])
                ]),
                _: 1
              }, 8, ["categorized-items", "initial-value", "menu-items", "categories", "link-item-rules", "no-scheduler", "onSubmit"]))
            ])
          ]),
          default: u(() => [
            n(q, {
              modelValue: c.value,
              "onUpdate:modelValue": t[3] || (t[3] = (s) => c.value = s),
              items: h.value,
              class: "mb-7 xs:mb-0 xs:px-32"
            }, null, 8, ["modelValue", "items"]),
            i("div", be, [
              n(ue, { "menu-store": e(a) }, null, 8, ["menu-store"]),
              n(B)
            ])
          ]),
          _: 1
        }, 8, ["heading"])
      ], 64);
    };
  }
});
export {
  Ge as default
};
