import { defineComponent as N, useModel as K, computed as B, resolveComponent as d, createBlock as P, openBlock as b, ref as L, watch as W, withCtx as _, createElementBlock as F, createElementVNode as I, Fragment as q, renderList as X, createVNode as u, unref as e, createCommentVNode as $, withModifiers as Q, onMounted as te, renderSlot as le, toDisplayString as h, createTextVNode as ae } from "vue";
import { useI18n as z, useCustomAttributes as ue, useCoreStore as re, isEmptyRule as oe, EMPTY_RULE as w } from "@feedmepos/mf-common";
import { _ as x } from "./FormItem.vue_vue_type_script_setup_true_lang-BmPAVphe.js";
import { u as D } from "./priceTier-CYn3f8Qi.js";
import { b as O } from "./app-5fxKLAzS.js";
import { FmButtonVariant as Z, useDialog as ne, components as ie, FmButtonColorThemeVariant as j } from "@feedmepos/ui-library";
import { m as G, f as Y, d as se, _ as me } from "./RuleView.vue_vue_type_script_setup_true_lang-DRUQOy4h.js";
import { L as R } from "./catalogSetting-B_CqlQ0S.js";
import { L as de } from "./LinkProductSideSheet-DUHaljek.js";
import { c as H } from "./check-C9mY6LiX.js";
import { u as pe, I as J, ao as ce } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
import { c as ve } from "./string-DpfFixWH.js";
const fe = /* @__PURE__ */ N({
  __name: "LinkPriceTier",
  props: {
    modelValue: { required: !0 },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(T) {
    const { t: y } = z(), r = K(T, "modelValue"), o = D(), a = B(() => o.priceTiers.value.map((V) => ({
      label: V.key,
      value: V.key
    })));
    return (V, g) => {
      const i = d("FmSelect");
      return b(), P(i, {
        items: a.value,
        "model-value": r.value ?? [],
        multiselect: !0,
        keepSelectionOrder: !0,
        "onUpdate:modelValue": g[0] || (g[0] = (s) => r.value = s)
      }, null, 8, ["items", "model-value"]);
    };
  }
}), _e = {
  class: "flex justify-end"
}, be = /* @__PURE__ */ N({
  __name: "PriceTierRuleEditor",
  props: {
    modelValue: {
      required: !0
    },
    modelModifiers: {}
  },
  emits: ["update:modelValue"],
  setup(T) {
    var k;
    const {
      t: y
    } = z(), r = K(T, "modelValue"), o = L((k = r.value) == null ? void 0 : k.map((l) => {
      var p, c;
      return {
        ...l,
        restaurantRule: {
          restaurantAttributes: G((p = l.restaurantRule) == null ? void 0 : p.restaurantAttributes),
          restaurantCustomAttributes: G((c = l.restaurantRule) == null ? void 0 : c.restaurantCustomAttributes)
        }
      };
    }));
    W(o, (l) => {
      r.value = l == null ? void 0 : l.map((p) => {
        var c, n;
        return {
          priceTier: p.priceTier,
          restaurantRule: {
            restaurantAttributes: Y((c = p.restaurantRule) == null ? void 0 : c.restaurantAttributes),
            restaurantCustomAttributes: Y((n = p.restaurantRule) == null ? void 0 : n.restaurantCustomAttributes)
          }
        };
      });
    }, {
      deep: !0
    });
    const a = D(), {
      attributes: V
    } = ue({
      valueSource: re().restaurants,
      entity: "restaurant"
    }), {
      restaurantAttributes: g
    } = se();
    function i(l, p, c) {
      o.value && o.value[l] && (oe(p) ? o.value[l].restaurantRule[c] = w : o.value[l].restaurantRule[c] = p);
    }
    const s = B(() => a.priceTiers.value.map((l) => ({
      value: l.key,
      label: l.key
    })));
    function t() {
      o.value = [...o.value || [], {
        priceTier: "",
        restaurantRule: {
          restaurantAttributes: w,
          restaurantCustomAttributes: w
        }
      }];
    }
    function A(l) {
      o.value && o.value.splice(l, 1);
    }
    return (l, p) => {
      const c = d("FmSelect"), n = d("fm-button"), v = d("FmCard"), E = d("FmButton");
      return b(), P(me, null, {
        default: _(() => [(b(!0), F(q, null, X(o.value, (M, S) => (b(), P(v, {
          key: S,
          class: "p-16 space-y-16",
          variant: "outlined"
        }, {
          default: _(() => [I("div", null, [u(c, {
            label: "Price groups",
            "label-mark": "required",
            items: s.value,
            "model-value": M.priceTier,
            rules: [(f) => !!f || e(y)("menu.common.validation.required_field")],
            "onUpdate:modelValue": (f) => M.priceTier = f
          }, null, 8, ["items", "model-value", "rules", "onUpdate:modelValue"])]), u(x, {
            label: e(y)("menu.link_product.rules.restaurant_filter")
          }, {
            default: _(() => {
              var f;
              return [u(e(O), {
                attributes: e(g),
                "model-value": (f = M.restaurantRule) == null ? void 0 : f.restaurantAttributes,
                "onUpdate:modelValue": (C) => i(S, C, "restaurantAttributes")
              }, null, 8, ["attributes", "model-value", "onUpdate:modelValue"])];
            }),
            _: 2
          }, 1032, ["label"]), u(x, {
            label: e(y)("menu.link_product.rules.restaurant_custom_attributes_filter")
          }, {
            default: _(() => {
              var f;
              return [u(e(O), {
                attributes: e(V),
                "model-value": (f = M.restaurantRule) == null ? void 0 : f.restaurantCustomAttributes,
                "onUpdate:modelValue": (C) => i(S, C, "restaurantCustomAttributes")
              }, null, 8, ["attributes", "model-value", "onUpdate:modelValue"])];
            }),
            _: 2
          }, 1032, ["label"]), I("div", _e, [u(n, {
            variant: e(Z).Tertiary,
            "prepend-icon": "delete",
            onClick: (f) => A(S)
          }, null, 8, ["variant", "onClick"])])]),
          _: 2
        }, 1024))), 128)), I("div", null, [u(E, {
          label: "Add rule",
          onClick: t
        })])]),
        _: 1
      });
    };
  }
}), Le = /* @__PURE__ */ N({
  __name: "LinkPriceTierSection",
  props: {
    modelValue: {},
    isMainCatalog: {
      type: Boolean
    },
    isV4: {
      type: Boolean
    }
  },
  emits: ["update:modelValue"],
  setup(T, {
    emit: y
  }) {
    const r = T, o = y, {
      t: a
    } = z(), V = D(), g = L(r.modelValue.priceTierRules && r.modelValue.priceTierRules.length > 0 ? R.Rules : R.Normal);
    function i(s) {
      o("update:modelValue", {
        ...r.modelValue,
        ...s
      });
    }
    return (s, t) => {
      const A = d("fm-radio"), k = d("fm-radio-group");
      return !s.isMainCatalog && s.isV4 && e(V).priceTiers.value.length > 0 ? (b(), P(x, {
        key: 0,
        label: e(a)("menu.price_tier.link_price_tier")
      }, {
        default: _(() => [u(k, {
          "model-value": g.value,
          "onUpdate:modelValue": t[4] || (t[4] = (l) => {
            g.value = l, l === e(R).Normal && i({
              priceTierRules: null
            });
          })
        }, {
          default: _(() => [u(A, {
            value: e(R).Normal,
            label: e(a)("menu.price_tier.link_price_group"),
            sublabel: e(a)("menu.price_tier.link_price_group_description")
          }, null, 8, ["value", "label", "sublabel"]), g.value === e(R).Normal ? (b(), F("div", {
            key: 0,
            onClick: t[1] || (t[1] = Q(() => {
            }, ["prevent"])),
            class: "pl-32"
          }, [u(fe, {
            "model-value": s.modelValue.usePriceTiers,
            "onUpdate:modelValue": t[0] || (t[0] = (l) => i({
              usePriceTiers: l
            }))
          }, null, 8, ["model-value"])])) : $("", !0), u(A, {
            value: e(R).Rules,
            label: e(a)("menu.price_tier.price_group_rule"),
            sublabel: e(a)("menu.price_tier.price_group_rule_description")
          }, null, 8, ["value", "label", "sublabel"]), g.value === e(R).Rules ? (b(), F("div", {
            key: 1,
            onClick: t[3] || (t[3] = Q(() => {
            }, ["prevent"])),
            class: "pl-32"
          }, [u(be, {
            "model-value": s.modelValue.priceTierRules,
            "onUpdate:modelValue": t[2] || (t[2] = (l) => i({
              priceTierRules: l
            }))
          }, null, 8, ["model-value"])])) : $("", !0)]),
          _: 1
        }, 8, ["model-value"])]),
        _: 1
      }, 8, ["label"])) : $("", !0);
    };
  }
}), ge = { class: "space-y-16" }, ke = { class: "ml-32 mt-16 space-y-8" }, Ve = {
  key: 0,
  class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary"
}, $e = /* @__PURE__ */ N({
  __name: "GroupMarkupPriceDialog",
  props: {
    modelValue: {},
    items: {},
    categories: {},
    action: {}
  },
  emits: ["update:model-value"],
  setup(T, { emit: y }) {
    const r = T, o = pe();
    ne();
    const { t: a } = z(), V = y, g = B(() => r.action === "add" ? a("menu.markup.dialog.title.add") : a("menu.markup.dialog.title.update")), i = L(!1), s = (n) => {
      H.isBoolean(n) ? i.value = n : i.value = !i.value;
    }, t = L(
      r.modelValue ? J(r.modelValue) : {
        percentage: 0,
        includeItems: null
      }
    );
    W(
      () => i.value,
      (n) => {
        n && (t.value = r.modelValue ? J(r.modelValue) : {
          percentage: 0,
          includeItems: null
        });
      }
    ), B(
      () => ce(o.variants, r.categories, r.items)
    );
    function A(n) {
      t.value = {
        ...t.value,
        includeItems: n
      };
    }
    const k = L(
      0
      /* ALL */
    );
    function l(n) {
      k.value = n, t.value = {
        ...t.value,
        includeItems: n === 0 ? null : []
      };
    }
    const p = B(() => [
      {
        label: a("menu.markup.dialog.options.all"),
        value: 0
        /* ALL */
      },
      {
        label: a("menu.markup.dialog.options.custom"),
        value: 1
        /* CUSTOM */
      }
    ]);
    async function c() {
      V("update:model-value", t.value), s(!1);
    }
    return te(() => {
      k.value = t.value && t.value.includeItems === null ? 0 : 1;
    }), (n, v) => {
      const E = d("fm-icon"), M = d("fm-stepper-field"), S = d("fm-radio"), f = d("fm-radio-group"), C = d("fm-button"), ee = d("fm-dialog");
      return b(), F(q, null, [
        le(n.$slots, "default", { trigger: s }),
        u(ee, {
          modelValue: i.value,
          "onUpdate:modelValue": v[4] || (v[4] = (U) => i.value = U),
          "is-component": e(ie).FmForm,
          "is-component-props": {
            onValidationSuccess: c
          }
        }, {
          "dialog-header": _(() => [
            ae(h(g.value), 1)
          ]),
          "dialog-footer": _(() => [
            u(C, {
              class: "sm:w-full xs:w-full ml-auto",
              label: "Cancel",
              variant: "tertiary",
              onClick: v[3] || (v[3] = (U) => s(!1))
            }),
            u(C, {
              label: e(ve)(n.action),
              class: "sm:w-full xs:w-full",
              size: "md",
              type: "submit",
              variant: "primary"
            }, null, 8, ["label"])
          ]),
          default: _(() => {
            var U;
            return [
              I("div", ge, [
                u(M, {
                  modelValue: t.value.percentage,
                  "onUpdate:modelValue": v[0] || (v[0] = (m) => t.value.percentage = m),
                  decimal: 0,
                  max: 100,
                  min: 0,
                  rules: [
                    (m) => e(H).isSet(m) && m >= 0 || e(a)("menu.markup.dialog.fields.percentage.required")
                  ],
                  label: e(a)("menu.markup.dialog.fields.percentage.label"),
                  placeholder: e(a)("menu.markup.dialog.fields.percentage.placeholder")
                }, {
                  prepend: _(() => [
                    u(E, { name: "percent" })
                  ]),
                  _: 1
                }, 8, ["modelValue", "rules", "label", "placeholder"]),
                I("div", null, [
                  u(f, {
                    modelValue: k.value,
                    "onUpdate:modelValue": [
                      v[1] || (v[1] = (m) => k.value = m),
                      l
                    ],
                    class: "space-y-8"
                  }, {
                    default: _(() => [
                      (b(!0), F(q, null, X(p.value, (m) => (b(), P(S, {
                        key: m.value,
                        label: m.label,
                        value: m.value
                      }, null, 8, ["label", "value"]))), 128))
                    ]),
                    _: 1
                  }, 8, ["modelValue"]),
                  I("div", ke, [
                    u(de, {
                      title: "Link products",
                      "categorized-items": e(o).categorizedItems,
                      "initial-value": t.value.includeItems || [],
                      "show-variant": !1,
                      onSubmit: v[2] || (v[2] = ({ items: m }) => A(m))
                    }, {
                      default: _(({ trigger: m }) => [
                        k.value === 1 ? (b(), P(C, {
                          key: 0,
                          "text-color": e(j).ColorPrimary,
                          "border-color": e(j).ColorPrimary,
                          variant: e(Z).Secondary,
                          label: e(a)("menu.markup.dialog.products.link"),
                          "prepend-icon": "link",
                          onClick: m
                        }, null, 8, ["text-color", "border-color", "variant", "label", "onClick"])) : $("", !0)
                      ]),
                      _: 1
                    }, 8, ["categorized-items", "initial-value"]),
                    (U = t.value.includeItems) != null && U.length ? (b(), F("p", Ve, h(e(a)("menu.markup.dialog.products.count", { count: t.value.includeItems.length })), 1)) : $("", !0)
                  ])
                ])
              ])
            ];
          }),
          _: 1
        }, 8, ["modelValue", "is-component", "is-component-props"])
      ], 64);
    };
  }
});
export {
  $e as _,
  Le as a
};
