import { defineComponent as ie, computed as Y, resolveComponent as _, createElementBlock as d, openBlock as u, createVNode as t, createCommentVNode as F, unref as n, toDisplayString as L, createElementVNode as h, withCtx as v, Fragment as N, renderList as M, createBlock as I, ref as H, Transition as se, createTextVNode as me } from "vue";
import { I as S, A as r, u as pe, J as ve, M as ue } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
import { useI18n as de } from "@feedmepos/mf-common";
import { components as _e } from "@feedmepos/ui-library";
import { _ as fe } from "./FormItem.vue_vue_type_script_setup_true_lang-BmPAVphe.js";
import { _ as ne } from "./RuleView.vue_vue_type_script_setup_true_lang-DRUQOy4h.js";
import { u as ye } from "./discardConfirm-BHni0LNu.js";
import { u as he } from "./menu-DNLXOwiM.js";
import { L as ge } from "./LinkProductSideSheet-DUHaljek.js";
const Ve = { class: "space-y-8" }, Fe = {
  key: 0,
  class: "space-y-16"
}, ke = { key: 0 }, be = {
  key: 1,
  class: "flex items-center"
}, Ee = { class: "flex flex-row items-center gap-8" }, Ce = { class: "flex flex-1 flex-wrap flex-row items-center gap-4" }, Ue = { key: 0 }, xe = { class: "w-[120px]" }, Se = "code", De = /* @__PURE__ */ ie({
  __name: "FilterForm",
  props: {
    modelValue: {}
  },
  emits: ["update:modelValue"],
  setup(V, { emit: G }) {
    const f = V, e = G, { categories: J } = he(), W = Y(() => J.value.map((s) => s.id === null ? { label: s.name, value: "" } : {
      label: s.name,
      value: s.id
    })), X = (s) => {
      s ? e("update:modelValue", []) : e("update:modelValue", void 0);
    }, { t: p } = de(), Z = [
      { label: p("menu.scheduler.dialog.sections.filter.types.code"), value: "code" },
      { label: p("menu.scheduler.dialog.sections.filter.types.category"), value: "category" }
    ], ee = () => {
      e("update:modelValue", [...f.modelValue || [], { type: Se, value: [""] }]);
    }, C = (s) => {
      const c = S(f.modelValue || []);
      c.splice(s, 1), e("update:modelValue", c);
    }, z = (s, c) => {
      const m = S(f.modelValue || []);
      m[s].type = c, c === "category" ? m[s].value = [] : m[s].value = [""], e("update:modelValue", m);
    }, a = (s) => {
      const c = S(f.modelValue || []);
      c[s].value.push(""), e("update:modelValue", c);
    }, D = (s, c) => {
      const m = S(f.modelValue || []);
      m[s].value.splice(c, 1), e("update:modelValue", m);
    }, le = (s, c) => {
      const m = S(f.modelValue || []);
      m[s].value = c, e("update:modelValue", m);
    }, O = (s, c, m) => {
      const w = S(f.modelValue || []);
      w[s].value[c] = m, e("update:modelValue", w);
    };
    return (s, c) => {
      var $, K;
      const m = _("FmSwitch"), w = _("FmIcon"), te = _("FmTooltip"), B = _("FmSelect"), P = _("FmButton"), q = _("FmTextField");
      return u(), d("div", Ve, [
        t(m, {
          "model-value": !!f.modelValue,
          value: "autoLink",
          label: n(p)("menu.scheduler.dialog.sections.autolink.label"),
          sublabel: n(p)("menu.scheduler.dialog.sections.autolink.sublabel"),
          "label-placement": "right",
          "onUpdate:modelValue": X
        }, null, 8, ["model-value", "label", "sublabel"]),
        f.modelValue ? (u(), d("div", Fe, [
          (($ = f.modelValue) == null ? void 0 : $.length) === 0 ? (u(), d("div", ke, L(n(p)("menu.scheduler.dialog.sections.autolink.all_items")), 1)) : F("", !0),
          ((K = f.modelValue) == null ? void 0 : K.length) > 0 ? (u(), d("div", be, [
            h("div", null, L(n(p)("menu.scheduler.dialog.sections.autolink.filter_message")), 1),
            t(te, {
              content: n(p)("menu.scheduler.dialog.sections.autolink.tooltip"),
              variant: "plain",
              "z-index": 999
            }, {
              default: v(() => [
                t(w, {
                  name: "help",
                  outline: "",
                  class: "ml-4"
                })
              ]),
              _: 1
            }, 8, ["content"])
          ])) : F("", !0),
          (u(!0), d(N, null, M(f.modelValue || [], (T, k) => (u(), d("div", { key: k }, [
            h("div", Ee, [
              h("div", Ce, [
                t(B, {
                  "model-value": T.type,
                  items: Z,
                  "onUpdate:modelValue": (b) => z(k, b)
                }, null, 8, ["model-value", "onUpdate:modelValue"]),
                h("div", null, L(n(p)("menu.scheduler.dialog.sections.filter.matches")), 1),
                T.type === "category" ? (u(), I(B, {
                  key: 0,
                  "model-value": T.value,
                  "onUpdate:modelValue": (b) => le(k, b),
                  items: W.value || [],
                  multiselect: "",
                  placeholder: n(p)("menu.scheduler.dialog.sections.filter.placeholder.category")
                }, null, 8, ["model-value", "onUpdate:modelValue", "items", "placeholder"])) : (u(), d(N, { key: 1 }, [
                  (u(!0), d(N, null, M(T.value, (b, U) => (u(), d("div", {
                    class: "flex items-center gap-4",
                    key: U
                  }, [
                    U > 0 ? (u(), d("div", Ue, L(n(p)("menu.scheduler.dialog.sections.filter.or")), 1)) : F("", !0),
                    h("div", xe, [
                      t(q, {
                        "model-value": b,
                        "onUpdate:modelValue": (Q) => O(k, U, Q)
                      }, {
                        append: v(() => [
                          T.value.length > 1 ? (u(), I(P, {
                            key: 0,
                            icon: "close",
                            onClick: (Q) => D(k, U),
                            variant: "tertiary"
                          }, null, 8, ["onClick"])) : F("", !0)
                        ]),
                        _: 2
                      }, 1032, ["model-value", "onUpdate:modelValue"])
                    ])
                  ]))), 128)),
                  t(P, {
                    icon: "add",
                    onClick: (b) => a(k),
                    variant: "tertiary"
                  }, null, 8, ["onClick"])
                ], 64))
              ]),
              t(P, {
                variant: "secondary",
                icon: "delete",
                onClick: (b) => C(k)
              }, null, 8, ["onClick"])
            ])
          ]))), 128)),
          t(P, {
            variant: "secondary",
            label: n(p)("menu.scheduler.dialog.sections.filter.add"),
            onClick: ee
          }, null, 8, ["label"])
        ])) : F("", !0)
      ]);
    };
  }
}), we = {
  key: 0,
  class: "pl-32"
}, Pe = { class: "flex flex-wrap gap-8" }, Te = {
  key: 0,
  class: "pl-32 flex flex-col items-start gap-16"
}, Ae = { class: "w-full" }, Le = {
  key: 0,
  class: "mt-8"
}, Ne = { class: "text-red-500 text-sm" }, Re = { class: "bg-fm-color-neutral-gray-100 px-16 py-8 border-b border-b-gray-200" }, Ye = { class: "px-16 py-8 flex-1" }, Me = { class: "px-16 py-8" }, Oe = { class: "flex gap-8 items-center justify-start" }, Ge = /* @__PURE__ */ ie({
  __name: "SchedulerDialog",
  props: {
    categorizedItems: {
      type: Array,
      required: !0
    },
    canApplyItems: {
      type: Boolean,
      default: !0
    }
  },
  emits: ["onComplete"],
  setup(V, { expose: G, emit: f }) {
    const { t: e } = de(), J = V;
    G({
      show: le,
      hide: O
    });
    const W = {
      [r.F_SCHEDULE_DAY.enum.monday]: e("menu.scheduler.days.monday"),
      [r.F_SCHEDULE_DAY.enum.tuesday]: e("menu.scheduler.days.tuesday"),
      [r.F_SCHEDULE_DAY.enum.wednesday]: e("menu.scheduler.days.wednesday"),
      [r.F_SCHEDULE_DAY.enum.thursday]: e("menu.scheduler.days.thursday"),
      [r.F_SCHEDULE_DAY.enum.friday]: e("menu.scheduler.days.friday"),
      [r.F_SCHEDULE_DAY.enum.saturday]: e("menu.scheduler.days.saturday"),
      [r.F_SCHEDULE_DAY.enum.sunday]: e("menu.scheduler.days.sunday")
    }, X = f;
    function p() {
      return {
        _id: "",
        name: "",
        items: [],
        groups: [],
        repeat: r.F_SCHEDULE_FREQUENCY.enum.daily,
        timePeriod: [],
        weekDay: []
      };
    }
    const Z = pe(), ee = Y(() => Z.version === r.F_MENU_VERSION.enum.v4), C = H("all"), z = H(p()), a = H(p()), D = H(!1);
    function le(i) {
      a.value = i ? S(i) : p(), z.value = S(a.value), C.value = a.value.timePeriod.length === 0 ? "all" : "custom", D.value = !0;
    }
    function O() {
      D.value = !1;
    }
    function s() {
      a.value.timePeriod.push({
        start: "00:00",
        end: "23:59"
      });
    }
    function c(i) {
      a.value.timePeriod.splice(i, 1);
    }
    function m(i) {
      const [l, y] = i.split(":").map(Number);
      return l * 60 + y;
    }
    function w(i, l) {
      const y = m(i), g = m(l);
      return y <= g ? [{ start: y, end: g }] : [
        { start: y, end: 24 * 60 - 1 },
        // Until end of day (23:59)
        { start: 0, end: g }
        // From start of next day
      ];
    }
    function te(i, l) {
      return Math.max(i.start, l.start) <= Math.min(i.end, l.end);
    }
    function B(i) {
      if (i.length <= 1) return null;
      for (let l = 0; l < i.length; l++)
        for (let y = l + 1; y < i.length; y++) {
          const g = i[l], A = i[y], ae = w(g.start, g.end), j = w(A.start, A.end);
          for (const x of ae)
            for (const oe of j)
              if (te(x, oe))
                return e("menu.scheduler.dialog.sections.period.overlap");
        }
      return null;
    }
    const P = H();
    function q() {
      return {
        ...a.value,
        timePeriod: C.value === "all" ? [] : a.value.timePeriod,
        weekDay: a.value.repeat === r.F_SCHEDULE_FREQUENCY.enum.daily ? [] : a.value.weekDay
      };
    }
    async function $() {
      U.value || (X("onComplete", q()), O());
    }
    const K = Y(() => a.value._id ? e("menu.scheduler.dialog.update.title") : e("menu.scheduler.dialog.add.title")), T = Y(() => a.value._id ? e("menu.scheduler.dialog.update.action") : e("menu.scheduler.dialog.add.action"));
    function k(i) {
      a.value.items = a.value.items.filter((l) => l._id !== i);
    }
    const b = Y(() => J.categorizedItems.reduce((i, l) => {
      const y = l.items.filter(
        (g) => a.value.items.some(({ _id: A }) => g._id === A)
      );
      return y.length && i.push({ ...l, items: y }), i;
    }, [])), U = Y(() => C.value === "custom" && a.value.timePeriod.length > 0 ? B(a.value.timePeriod) : null), Q = ye(
      () => !ve.isEqual(z.value, q()),
      () => {
        D.value = !1;
      }
    );
    return (i, l) => {
      const y = _("FmTextField"), g = _("FmRadio"), A = _("FmRadioGroup"), ae = _("FmCheckbox"), j = _("FmTimePicker"), x = _("FmButton"), oe = _("FmSpacer"), re = _("FmForm"), ce = _("FmSideSheet");
      return u(), I(ce, {
        modelValue: D.value,
        "onUpdate:modelValue": l[7] || (l[7] = (o) => D.value = o),
        header: K.value,
        "max-width": 560,
        "is-container": n(_e).FmForm,
        "is-container-props": {
          onValidationSuccess: $,
          blameFormChildOnValidationFailed: !0,
          class: "flex flex-col h-full"
        },
        "onOn:clickedAway": n(Q)
      }, {
        "side-sheet-footer": v(() => [
          h("div", Oe, [
            t(x, {
              label: T.value,
              size: "lg",
              variant: "primary",
              onClick: l[6] || (l[6] = () => {
                var o;
                return (o = P.value) == null ? void 0 : o.validateInputs();
              })
            }, null, 8, ["label"]),
            t(x, {
              label: n(e)("menu.scheduler.dialog.actions.cancel"),
              size: "lg",
              variant: "tertiary",
              onClick: O
            }, null, 8, ["label"])
          ])
        ]),
        default: v(() => [
          t(re, {
            ref_key: "formRef",
            ref: P,
            class: "flex flex-col flex-1 overflow-hidden",
            onValidationSuccess: $
          }, {
            default: v(() => [
              t(ne, {
                title: n(e)("menu.scheduler.dialog.sections.detail.title")
              }, {
                default: v(() => [
                  t(y, {
                    autofocus: "",
                    modelValue: a.value.name,
                    "onUpdate:modelValue": l[0] || (l[0] = (o) => a.value.name = o),
                    rules: [(o) => !!o || n(e)("menu.scheduler.dialog.sections.detail.name.required")],
                    label: n(e)("menu.scheduler.dialog.sections.detail.name.label"),
                    placeholder: n(e)("menu.scheduler.dialog.sections.detail.name.placeholder")
                  }, null, 8, ["modelValue", "rules", "label", "placeholder"])
                ]),
                _: 1
              }, 8, ["title"]),
              t(ne, {
                title: n(e)("menu.scheduler.dialog.sections.availability.title")
              }, {
                default: v(() => [
                  h("div", null, [
                    t(A, {
                      modelValue: a.value.repeat,
                      "onUpdate:modelValue": l[1] || (l[1] = (o) => a.value.repeat = o)
                    }, {
                      default: v(() => [
                        t(g, {
                          label: n(e)("menu.scheduler.dialog.sections.availability.daily"),
                          value: n(r.F_SCHEDULE_FREQUENCY).enum.daily
                        }, null, 8, ["label", "value"]),
                        t(g, {
                          label: n(e)("menu.scheduler.dialog.sections.availability.weekly"),
                          value: n(r.F_SCHEDULE_FREQUENCY).enum.weekly
                        }, null, 8, ["label", "value"])
                      ]),
                      _: 1
                    }, 8, ["modelValue"]),
                    t(se, { name: "expand" }, {
                      default: v(() => [
                        a.value.repeat === n(r.F_SCHEDULE_FREQUENCY).enum.weekly ? (u(), d("div", we, [
                          h("div", Pe, [
                            (u(), d(N, null, M(W, (o, E) => t(ae, {
                              key: E,
                              modelValue: a.value.weekDay,
                              "onUpdate:modelValue": l[2] || (l[2] = (R) => a.value.weekDay = R),
                              label: o,
                              value: E
                            }, null, 8, ["modelValue", "label", "value"])), 64))
                          ])
                        ])) : F("", !0)
                      ]),
                      _: 1
                    })
                  ]),
                  h("div", null, [
                    t(A, {
                      label: n(e)("menu.scheduler.dialog.sections.period.title"),
                      modelValue: C.value,
                      "onUpdate:modelValue": l[3] || (l[3] = (o) => C.value = o)
                    }, {
                      default: v(() => [
                        t(g, {
                          label: n(e)("menu.scheduler.dialog.sections.period.all_day"),
                          value: "all"
                        }, null, 8, ["label"]),
                        t(g, {
                          label: n(e)("menu.scheduler.dialog.sections.period.custom"),
                          value: "custom"
                        }, null, 8, ["label"])
                      ]),
                      _: 1
                    }, 8, ["label", "modelValue"]),
                    t(se, { name: "expand" }, {
                      default: v(() => [
                        C.value === "custom" ? (u(), d("div", Te, [
                          h("div", Ae, [
                            (u(!0), d(N, null, M(a.value.timePeriod, (o, E) => (u(), d("div", {
                              key: E,
                              class: "w-full flex gap-8 items-center"
                            }, [
                              t(j, {
                                modelValue: o.start,
                                "onUpdate:modelValue": (R) => o.start = R,
                                class: "flex-1"
                              }, null, 8, ["modelValue", "onUpdate:modelValue"]),
                              l[8] || (l[8] = me(" - ")),
                              t(j, {
                                modelValue: o.end,
                                "onUpdate:modelValue": (R) => o.end = R,
                                class: "flex-1"
                              }, null, 8, ["modelValue", "onUpdate:modelValue"]),
                              t(x, {
                                icon: "close",
                                variant: "tertiary",
                                onClick: (R) => c(E)
                              }, null, 8, ["onClick"])
                            ]))), 128)),
                            U.value ? (u(), d("div", Le, [
                              h("div", Ne, L(U.value), 1)
                            ])) : F("", !0)
                          ]),
                          t(x, {
                            icon: "add",
                            label: n(e)("menu.scheduler.dialog.sections.period.add"),
                            variant: "secondary",
                            "text-color": "primary",
                            "border-color": "primary",
                            onClick: s
                          }, null, 8, ["label"])
                        ])) : F("", !0)
                      ]),
                      _: 1
                    })
                  ]),
                  ee.value ? (u(), I(fe, {
                    key: 0,
                    label: n(e)("menu.scheduler.dialog.sections.autolink.title")
                  }, {
                    default: v(() => [
                      t(De, {
                        modelValue: a.value.filters,
                        "onUpdate:modelValue": l[4] || (l[4] = (o) => a.value.filters = o)
                      }, null, 8, ["modelValue"])
                    ]),
                    _: 1
                  }, 8, ["label"])) : F("", !0)
                ]),
                _: 1
              }, 8, ["title"]),
              V.canApplyItems ? (u(), I(ne, {
                key: 0,
                title: n(e)("menu.scheduler.dialog.sections.products.title")
              }, {
                "append-title": v(() => [
                  t(oe),
                  t(ge, {
                    "categorized-items": V.categorizedItems,
                    "initial-value": a.value.items,
                    onSubmit: l[5] || (l[5] = ({ items: o }) => a.value.items = o)
                  }, {
                    default: v(({ trigger: o }) => [
                      t(x, {
                        icon: "link",
                        label: n(e)("menu.scheduler.dialog.sections.products.link"),
                        variant: "secondary",
                        "text-color": "primary",
                        "border-color": "primary",
                        onClick: o
                      }, null, 8, ["label", "onClick"])
                    ]),
                    _: 1
                  }, 8, ["categorized-items", "initial-value"])
                ]),
                default: v(() => [
                  (u(!0), d(N, null, M(b.value, (o) => (u(), d("div", {
                    key: o.id
                  }, [
                    h("div", Re, L(o.name), 1),
                    (u(!0), d(N, null, M(o.items, (E) => (u(), d("div", {
                      key: E._id,
                      class: "flex border-b border-b-gray-100 items-center"
                    }, [
                      h("div", Ye, L(E.name), 1),
                      h("div", Me, [
                        t(x, {
                          icon: "delete",
                          variant: "tertiary",
                          "text-color": "neutral-gray-400",
                          onClick: () => k(E._id)
                        }, null, 8, ["onClick"])
                      ])
                    ]))), 128))
                  ]))), 128))
                ]),
                _: 1
              }, 8, ["title"])) : F("", !0)
            ]),
            _: 1
          }, 512)
        ]),
        _: 1
      }, 8, ["modelValue", "header", "is-container", "is-container-props", "onOn:clickedAway"]);
    };
  }
});
function Je(V) {
  return {
    module: r.F_MENU_MODULE_V4_KEY.enum.scheduler,
    operation: ue.F_OPERATION_TYPE.create,
    data: r.FdoMenuV4Scheduler.parse(V)
  };
}
function We(V) {
  return {
    module: r.F_MENU_MODULE_V4_KEY.enum.scheduler,
    operation: ue.F_OPERATION_TYPE.update,
    data: r.FdoMenuV4Scheduler.parse(V)
  };
}
function Xe(V) {
  return {
    module: r.F_MENU_MODULE_V4_KEY.enum.scheduler,
    operation: ue.F_OPERATION_TYPE.delete,
    data: V._id
  };
}
export {
  Ge as _,
  Je as c,
  Xe as d,
  We as u
};
