import { defineComponent as ne, computed as p, ref as se, watch as ue, watchEffect as ie, resolveComponent as m, createElementBlock as V, openBlock as r, normalizeClass as H, createVNode as s, withCtx as c, createElementVNode as v, createBlock as g, createCommentVNode as k, unref as e, Fragment as D, renderList as B, createTextVNode as re, toDisplayString as N } from "vue";
import { u as me, G as ce, A as f, Q as de, B as pe, I as w } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
import { useCoreStore as ve, useI18n as ge } from "@feedmepos/mf-common";
import { useSnackbar as fe, useDialog as _e, FmButtonVariant as $, FmButtonColorThemeVariant as P, components as be } from "@feedmepos/ui-library";
import { _ as E } from "./FormItem.vue_vue_type_script_setup_true_lang-BmPAVphe.js";
import { _ as ye } from "./RuleView.vue_vue_type_script_setup_true_lang-DRUQOy4h.js";
import { _ as z, a as ke } from "./GroupMarkupPriceDialog.vue_vue_type_script_setup_true_lang-BFroO4RA.js";
import { C as _, a as x } from "./catalogSetting-B_CqlQ0S.js";
import { C as xe } from "./catalog-rNLjUMn-.js";
const Ce = {
  class: /* @__PURE__ */ H(["overflow-scroll", "flex-1", "xs:px-16 xs:py-16", "pt-16"])
}, Oe = {
  class: "space-y-32"
}, Se = {
  key: 0,
  class: "pl-32 space-x-8"
}, Me = {
  class: "pl-[60px] space-y-16"
}, Ve = {
  class: "space-x-16 flex items-center"
}, Fe = {
  class: "flex-1 space-y-4"
}, Re = {
  class: "fm-typo-en-body-lg-400"
}, Ue = {
  class: "fm-typo-en-body-md-400"
}, he = {
  class: "flex justify-end"
}, ze = /* @__PURE__ */ ne({
  __name: "Setting",
  setup(Ne) {
    const F = ve(), u = me(), j = fe(), A = ce(j), {
      minor: q
    } = A, G = _e(), {
      t: n
    } = ge(), O = p(() => u.currentCatalog), b = p(() => !O.value), S = p(() => u.version === f.F_MENU_VERSION.enum.v4), {
      updateMenu: J
    } = de(A), l = se(_.initCatalogSetting()), Q = p(() => u.catalogs.filter((t) => t._id !== u.state.currentCatalogId).map((t) => t.name)), W = p(() => u.state.restaurants.filter((t) => [...t.additionalCatalogs, t.inHouseDelivery, ...t.linkedDeliveryCatalogs.map((o) => o.catalog), t.pickupCatalog, t.takeawayCatalog, t.catalogId].includes(u.state.currentCatalogId)).map((t) => t.name));
    function T() {
      return W.value.length > 0 ? s("div", {
        class: ["flex items-center", "bg-fm-color-system-warning-100", "rounded-lg", "py-16 px-24 space-x-8"]
      }, [s(be.FmIcon, {
        color: "system-warning-300",
        name: "warning"
      }, null), s("p", {
        class: "fm-typo-en-body-lg-400"
      }, [n("menu.setting.catalog.warnings.delivery")])]) : null;
    }
    function I() {
      const t = O.value;
      l.value = t ? _.fromCatalog(t, S.value) : _.fromMainCatalog(u.state.menu.masterCatalogSetting);
    }
    ue(() => u.state.currentCatalogId, I);
    const R = p(() => {
      if (!F.currentCountry.value) return [];
      const t = l.value.taxSetting.mode === x.MANUAL ? l.value.taxSetting.inclusive ?? [] : [];
      return pe.Country.getCountry(F.currentCountry.value).taxSystems.map((i) => {
        const d = t.find((C) => C.systemCode === i.code);
        return {
          inclusive: (d == null ? void 0 : d.inclusive) || !1,
          systemCode: i.code
        };
      });
    });
    function Y(t) {
      const o = l.value.taxSetting, i = o.mode === x.AUTO ? _.manualTax(R.value) : w(o);
      i.inclusive ?? (i.inclusive = []);
      const d = i.inclusive.findIndex((C) => C.systemCode === t.systemCode);
      d < 0 ? i.inclusive.push(t) : i.inclusive.splice(d, 1, t), U.value = i;
    }
    ie(async () => {
      F.currentBusiness.value && (b.value && !u.state.menu._id || I());
    });
    const U = p({
      get: () => l.value.taxSetting,
      set: (t) => {
        l.value.taxSetting = t;
      }
    }), K = async () => {
      const t = _.toCatalog(l.value);
      O.value ? await new xe({
        ...O.value,
        ...t
      }, u, J, G).update() : await q(async () => {
        await u.updateMainCatalogSetting({
          inclusiveTaxes: t.inclusiveTaxes
        });
      }, {
        successMessage: "Main catalog updated",
        customId: u.state.menu._id
      });
    };
    function X(t, o) {
      const i = w(l.value);
      i.markupOptions && (i.markupOptions[t] = o, l.value = i);
    }
    function Z(t) {
      const o = w(l.value);
      o.markupOptions && (o.markupOptions.splice(t, 1), l.value = o);
    }
    return (t, o) => {
      const i = m("fm-text-field"), d = m("fm-radio"), C = m("fm-radio-group"), ee = m("fm-checkbox"), L = m("fm-switch"), te = m("fm-select"), h = m("fm-button"), ae = m("fm-chip"), le = m("fm-card"), oe = m("fm-form");
      return r(), V("div", Ce, [s(oe, {
        class: H(["space-y-40 max-w-[751px]", "h-fit"]),
        "blame-form-child-on-validation-failed": "",
        onValidationSuccess: K
      }, {
        default: c(() => [v("div", Oe, [b.value ? k("", !0) : (r(), g(ye, {
          key: 0,
          title: e(n)("menu.setting.catalog.title")
        }, {
          default: c(() => [s(i, {
            modelValue: l.value.name,
            "onUpdate:modelValue": o[0] || (o[0] = (a) => l.value.name = a),
            rules: [(a) => !Q.value.includes(a.trim()) || e(n)("menu.setting.catalog.fields.name.used"), (a) => !!a.trim() || e(n)("menu.setting.catalog.fields.name.required")],
            label: e(n)("menu.setting.catalog.fields.name.label")
          }, null, 8, ["modelValue", "rules", "label"]), s(T)]),
          _: 1
        }, 8, ["title"])), s(E, {
          label: e(n)("menu.setting.tax.title")
        }, {
          default: c(() => [s(C, {
            "model-value": l.value.taxSetting.mode,
            "onUpdate:modelValue": o[1] || (o[1] = (a) => {
              a === e(x).AUTO ? U.value = e(_).autoTax() : U.value = e(_).manualTax(R.value);
            })
          }, {
            default: c(() => [s(d, {
              value: e(x).AUTO,
              label: e(n)("menu.setting.tax.modes.auto.label"),
              sublabel: e(n)("menu.setting.tax.modes.auto.sublabel")
            }, null, 8, ["value", "label", "sublabel"]), s(d, {
              value: e(x).MANUAL,
              label: e(n)("menu.setting.tax.modes.manual.label"),
              sublabel: e(n)("menu.setting.tax.modes.manual.sublabel")
            }, null, 8, ["value", "label", "sublabel"])]),
            _: 1
          }, 8, ["model-value"]), l.value.taxSetting.mode === e(x).MANUAL ? (r(), V("div", Se, [(r(!0), V(D, null, B(R.value, (a) => (r(), g(ee, {
            key: a.systemCode,
            "model-value": a.inclusive,
            value: !0,
            label: a.systemCode + " inclusive",
            "onUpdate:modelValue": (y) => {
              Y({
                ...a,
                inclusive: y
              });
            }
          }, null, 8, ["model-value", "label", "onUpdate:modelValue"]))), 128))])) : k("", !0)]),
          _: 1
        }, 8, ["label"]), !b.value && S.value ? (r(), g(E, {
          key: 1,
          label: e(n)("menu.setting.link.title")
        }, {
          default: c(() => [s(L, {
            "model-value": l.value.orderFrom && l.value.orderFrom !== e(f.F_ORDER_FROM).enum.NONE,
            label: e(n)("menu.setting.link.auto_link.label"),
            "label-placement": "right",
            sublabel: e(n)("menu.setting.link.auto_link.sublabel"),
            "onUpdate:modelValue": o[2] || (o[2] = (a) => l.value.orderFrom = a ? e(f.F_ORDER_FROM).enum.ALL : e(f.F_ORDER_FROM).enum.NONE)
          }, null, 8, ["model-value", "label", "sublabel"]), l.value.orderFrom !== e(f.F_ORDER_FROM).enum.NONE ? (r(), g(te, {
            key: 0,
            class: "ml-[60px]",
            items: [{
              label: "Available for all",
              value: e(f.F_ORDER_FROM).enum.ALL
            }, {
              label: "Order on POS only",
              value: e(f.F_ORDER_FROM).enum.POS_ONLY
            }],
            "model-value": l.value.orderFrom,
            "onUpdate:modelValue": o[3] || (o[3] = (a) => l.value.orderFrom = a)
          }, null, 8, ["items", "model-value"])) : k("", !0)]),
          _: 1
        }, 8, ["label"])) : k("", !0), !b.value && S.value ? (r(), g(E, {
          key: 2,
          label: e(n)("menu.setting.markup.title")
        }, {
          default: c(() => [s(L, {
            "model-value": !!l.value.markupOptions,
            label: e(n)("menu.setting.markup.auto_markup.label"),
            "label-placement": "right",
            sublabel: e(n)("menu.setting.markup.auto_markup.sublabel"),
            "onUpdate:modelValue": o[4] || (o[4] = (a) => l.value.markupOptions = a ? [] : null)
          }, null, 8, ["model-value", "label", "sublabel"]), v("div", Me, [s(z, {
            categories: e(u).categories,
            items: e(u).items,
            action: "add",
            "onUpdate:modelValue": o[5] || (o[5] = (a) => {
              a && (l.value.markupOptions = [...l.value.markupOptions ?? [], a]);
            })
          }, {
            default: c(({
              trigger: a
            }) => [s(h, {
              "text-color": e(P).ColorPrimary,
              "border-color": e(P).ColorPrimary,
              variant: e($).Secondary,
              label: "Add markup configuration",
              "prepend-icon": "add",
              onClick: a
            }, null, 8, ["text-color", "border-color", "variant", "onClick"])]),
            _: 1
          }, 8, ["categories", "items"]), (r(!0), V(D, null, B(l.value.markupOptions, (a, y) => (r(), g(z, {
            key: y,
            categories: e(u).categories,
            items: e(u).items,
            "model-value": a,
            action: "update",
            "onUpdate:modelValue": (M) => {
              M && X(y, M);
            }
          }, {
            default: c(({
              trigger: M
            }) => [s(le, {
              id: JSON.stringify(a),
              class: "py-12 px-16 cursor-pointer",
              variant: "outlined",
              onClick: M
            }, {
              default: c(() => [v("div", Ve, [v("div", Fe, [s(ae, {
                class: "text-fm-color-typo-info bg-fm-color-system-info-100 font-semibold"
              }, {
                default: c(() => [re(" Markup percentage: " + N(a.percentage) + "% ", 1)]),
                _: 2
              }, 1024), v("p", Re, N(e(n)("menu.setting.markup.config", {
                number: y + 1
              })), 1), v("p", Ue, N(a.includeItems ? e(n)("menu.setting.markup.products.linked", {
                count: a.includeItems.length
              }) : e(n)("menu.setting.markup.products.all")), 1)]), s(h, {
                variant: e($).Tertiary,
                "prepend-icon": "delete",
                onClick: (we) => Z(y)
              }, null, 8, ["variant", "onClick"])])]),
              _: 2
            }, 1032, ["id", "onClick"])]),
            _: 2
          }, 1032, ["categories", "items", "model-value", "onUpdate:modelValue"]))), 128))])]),
          _: 1
        }, 8, ["label"])) : k("", !0), s(ke, {
          modelValue: l.value,
          "onUpdate:modelValue": o[6] || (o[6] = (a) => l.value = a),
          "is-main-catalog": b.value,
          "is-v4": S.value
        }, null, 8, ["modelValue", "is-main-catalog", "is-v4"]), b.value ? (r(), g(T, {
          key: 3
        })) : k("", !0)]), v("div", he, [s(h, {
          label: e(n)("common.save"),
          type: "submit"
        }, null, 8, ["label"])])]),
        _: 1
      })]);
    };
  }
});
export {
  ze as default
};
