import { B as S, A, u as K, I as O, D as q, J as R } from "./index.vue_vue_type_script_setup_true_lang-BMVa5UfU.js";
import { defineComponent as T, ref as f, computed as B, watch as L, onMounted as z, onBeforeUnmount as P, resolveComponent as F, createBlock as N, openBlock as M, withModifiers as D, withCtx as g, renderSlot as U, createElementBlock as W, Fragment as j, createVNode as c, unref as i, createElementVNode as C, createCommentVNode as H, toDisplayString as J } from "vue";
import { useI18n as I } from "@feedmepos/mf-common";
import { components as Y } from "@feedmepos/ui-library";
import { _ as Z } from "./RuleView.vue_vue_type_script_setup_true_lang-DRUQOy4h.js";
import { u as G } from "./discardConfirm-BHni0LNu.js";
import { _ as Q } from "./ApplyProduct.vue_vue_type_script_setup_true_lang-B8Tcqib_.js";
import { c as X } from "./check-C9mY6LiX.js";
import { f as ee } from "./currency-DBI5JSrw.js";
import { c as ae } from "./string-DpfFixWH.js";
const te = /* @__PURE__ */ T({
  __name: "CurrencyInput",
  props: {
    modelValue: {},
    label: {},
    placeholder: {},
    nullable: { type: Boolean },
    showCurrency: { type: Boolean },
    min: {},
    max: {},
    required: { type: [Boolean, String] },
    rules: {},
    disable: { type: Boolean },
    minLength: {},
    maxLength: {},
    inputmode: {},
    type: {},
    readonly: { type: Boolean },
    labelMark: {},
    prependIcon: {},
    appendIcon: {},
    showValidBorder: { type: Boolean },
    labelInfo: {},
    showWordCount: { type: Boolean },
    invalid: { type: Boolean },
    autofocus: { type: Boolean },
    formatter: { type: Function },
    decimal: {},
    datalist: {},
    shiftDatalist: { type: Boolean },
    datalistMaxHeight: {},
    datalistMinHeight: {},
    offsetDatalist: {},
    datalistPlacement: {},
    datalistZIndex: {},
    datalistWidth: {},
    disabled: { type: Boolean },
    focused: { type: Boolean },
    helperText: {},
    helperState: {}
  },
  emits: ["update:model-value"],
  setup(y, { emit: m }) {
    const a = y, { t: n } = I(), d = f(!1), v = f(!1), r = f(), x = B(() => a.modelValue ? (v.value && !d.value && (d.value = !0), S.Dinero.fromFdoDinero(a.modelValue).toUnit().toFixed(2)) : "");
    L(
      () => v.value,
      (e) => {
        var t, l, o, E, w;
        e ? (l = (t = r.value) == null ? void 0 : t.inputEl) == null || l.select() : (d.value = !1, (o = r.value) != null && o.inputEl && k((w = (E = r.value) == null ? void 0 : E.inputEl) == null ? void 0 : w.value));
      }
    );
    const V = m, u = B(() => typeof a.required == "string" ? a.required : n("menu.common.validation.field_required", {
      field: a.label ?? n("menu.currency.input.field")
    })), b = [
      (e) => a.required ? !!e || u.value : !0,
      (e) => a.min !== void 0 && e && parseFloat(e.toString()) < a.min ? n("menu.common.validation.min_value", { value: a.min }) : !0,
      (e) => a.max !== void 0 && e && parseFloat(e.toString()) > a.max ? n("menu.common.validation.max_value", { value: a.max }) : !0,
      ...a.rules ?? []
    ];
    function k(e) {
      if (typeof e != "number" && !e && a.nullable)
        V("update:model-value", void 0);
      else {
        if (typeof e == "string" && e === "-")
          return;
        let t = parseFloat((e || "").toString());
        t = Number.isNaN(t) ? 0 : t, V("update:model-value", S.Dinero.fromNumber({ number: t }).toObject());
      }
    }
    const s = B(() => typeof a.min == "number" && a.min >= 0), _ = (e) => {
      var t, l, o;
      if (!(e.ctrlKey || e.metaKey)) {
        if (e.key === "Enter") {
          (t = r.value) != null && t.inputEl && k((o = (l = r.value) == null ? void 0 : l.inputEl) == null ? void 0 : o.value);
          return;
        }
        if (e.key === "-" && s.value) {
          e.preventDefault();
          return;
        }
        e.key >= "0" && e.key <= "9" || e.key === "." || e.key === "," || e.key === "-" || e.key === "Backspace" || e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "Tab" || e.preventDefault();
      }
    };
    return z(() => {
      var e;
      r.value && ((e = r.value.inputEl) == null || e.addEventListener("keydown", _));
    }), P(() => {
      var e;
      r.value && ((e = r.value.inputEl) == null || e.removeEventListener("keydown", _));
    }), (e, t) => {
      const l = F("fm-text-field");
      return M(), N(l, {
        ref_key: "inputRef",
        ref: r,
        autofocus: a.autofocus,
        disabled: a.disable,
        label: e.label,
        "model-value": x.value,
        placeholder: a.placeholder,
        "prepend-icon": e.showCurrency ? "attach_money" : void 0,
        rules: b,
        inputmode: "decimal",
        onFocusChanged: t[0] || (t[0] = (o) => v.value = o),
        onWheel: t[1] || (t[1] = D(() => {
        }, ["prevent"])),
        onTouchmove: t[2] || (t[2] = D(() => {
        }, ["prevent"])),
        onScroll: t[3] || (t[3] = D(() => {
        }, ["prevent"]))
      }, {
        append: g(() => [
          U(e.$slots, "append")
        ]),
        _: 3
      }, 8, ["autofocus", "disabled", "label", "model-value", "placeholder", "prepend-icon"]);
    };
  }
});
function be(y) {
  return y.map((m) => ({
    module: A.F_MENU_MODULE_V4_KEY.enum.item,
    id: m._id,
    discriminator: m.combinationKey,
    data: void 0
  }));
}
const le = { class: "fm-typo-en-title-md-600" }, oe = { class: "space-y-32" }, ne = { class: "flex gap-8 items-center justify-start" }, ie = /* @__PURE__ */ T({
  __name: "Form",
  props: {
    action: {},
    initialValue: {},
    fallback: {},
    applyProduct: { type: Boolean },
    bindToVariant: { type: Boolean }
  },
  emits: ["update:takeaway"],
  setup(y, { expose: m, emit: a }) {
    const { t: n } = I(), d = y, v = a, r = K(), x = B(() => r.rules.takeaway), V = f(!1), u = f(!1), b = (l) => {
      X.isBoolean(l) ? u.value = l : u.value = !u.value;
    };
    function k() {
      var o;
      const l = {
        ...q.generator.initMenuV4Takeaway(),
        usedBy: [],
        ...O(d.initialValue ?? {})
      };
      return (o = d.fallback) != null && o.price && (l.price = null), l;
    }
    const s = f(k()), _ = B(() => d.action === "add" ? n("menu.takeaway.add") : n("menu.takeaway.update")), e = G(
      () => !R.isEqual(
        s.value,
        d.initialValue || {
          ...q.generator.initMenuV4Takeaway(),
          usedBy: []
        }
      ),
      () => u.value = !1
    );
    function t() {
      v("update:takeaway", s.value), b(!1);
    }
    return L(
      () => u.value,
      () => {
        u.value && (s.value = k());
      }
    ), m({
      trigger: b,
      show: u
    }), (l, o) => {
      const E = F("fm-text-field"), w = F("fm-button"), $ = F("fm-side-sheet");
      return M(), W(j, null, [
        U(l.$slots, "default", { trigger: b }),
        c($, {
          id: "group-form",
          modelValue: u.value,
          "onUpdate:modelValue": o[4] || (o[4] = (p) => u.value = p),
          "is-container": i(Y).FmForm,
          "is-container-props": {
            onValidationSuccess: t,
            blameFormChildOnValidationFailed: !0
          },
          "max-width": 560,
          "onOn:clickedAway": i(e)
        }, {
          "side-sheet-header": g(() => [
            C("p", le, J(_.value), 1)
          ]),
          "side-sheet-footer": g(() => [
            C("div", ne, [
              c(w, {
                label: i(ae)(i(n)(`menu.common.actions.${l.action}`)),
                loading: V.value,
                size: "lg",
                type: "submit",
                variant: "primary"
              }, null, 8, ["label", "loading"]),
              c(w, {
                label: i(n)("menu.common.actions.cancel"),
                size: "lg",
                variant: "tertiary",
                onClick: o[3] || (o[3] = () => u.value = !1)
              }, null, 8, ["label"])
            ])
          ]),
          default: g(() => [
            C("div", oe, [
              c(Z, null, {
                default: g(() => {
                  var p;
                  return [
                    c(E, {
                      modelValue: s.value.name,
                      "onUpdate:modelValue": o[0] || (o[0] = (h) => s.value.name = h),
                      disabled: !x.value.name,
                      rules: [
                        (h) => !!h || i(n)("menu.common.validation.required", {
                          field: i(n)("menu.takeaway.columns.title").toLowerCase()
                        })
                      ],
                      autofocus: "",
                      label: i(n)("menu.takeaway.columns.title"),
                      placeholder: i(n)("menu.takeaway.placeholders.title"),
                      required: "",
                      title: i(n)("menu.takeaway.columns.title")
                    }, null, 8, ["modelValue", "disabled", "rules", "label", "placeholder", "title"]),
                    c(te, {
                      modelValue: s.value.price,
                      "onUpdate:modelValue": o[1] || (o[1] = (h) => s.value.price = h),
                      min: 0,
                      nullable: !!l.fallback,
                      placeholder: (p = l.fallback) != null && p.price ? i(ee)(l.fallback.price, !1) : void 0,
                      label: i(n)("menu.takeaway.columns.price"),
                      "show-currency": "",
                      title: i(n)("menu.takeaway.columns.price")
                    }, null, 8, ["modelValue", "nullable", "placeholder", "label", "title"])
                  ];
                }),
                _: 1
              }),
              l.applyProduct ? (M(), N(Q, {
                key: 0,
                overrides: s.value.usedBy,
                "onUpdate:overrides": o[2] || (o[2] = (p) => s.value.usedBy = p),
                "select-variant": l.bindToVariant,
                editable: "",
                title: i(n)("menu.common.labels.product")
              }, null, 8, ["overrides", "select-variant", "title"])) : H("", !0)
            ])
          ]),
          _: 1
        }, 8, ["modelValue", "is-container", "is-container-props", "onOn:clickedAway"])
      ], 64);
    };
  }
}), ke = ie;
export {
  ke as T,
  te as _,
  ie as a,
  be as l
};
