import { defineComponent as W, ref as A, resolveComponent as v, createElementBlock as E, openBlock as I, Fragment as B, createElementVNode as g, createVNode as c, normalizeClass as T, withCtx as _, toDisplayString as S, unref as i, h as G, watch as O, onMounted as K, nextTick as M, readonly as N, getCurrentInstance as U, getCurrentScope as L, onScopeDispose as $ } from "vue";
import { useI18n as q, useCustomAttributes as H, useCoreStore as J } from "@feedmepos/mf-common";
import { components as Q } from "@feedmepos/ui-library";
import { d as X, _ as k } from "./RuleView.vue_vue_type_script_setup_true_lang-DRUQOy4h.js";
const Y = {
  class: /* @__PURE__ */ T(["fm-typo-en-body-md-600 select-none text-ellipsis overflow-hidden whitespace-nowrap", "text-fm-color-neutral-gray-400"])
}, Z = {
  class: "fm-typo-en-title-sm-600"
}, ee = {
  class: "max-h-[60vh] flex-1 overflow-y-auto min-h-0"
}, me = /* @__PURE__ */ W({
  __name: "RestaurantAttributesSelector",
  props: {
    fullWidth: {
      type: Boolean,
      default: !1
    },
    currentRestaurantAttrParams: {}
  },
  emits: ["confirm"],
  setup(e, {
    emit: n
  }) {
    const o = e, {
      t
    } = q(), {
      attributes: r
    } = H({
      valueSource: J().restaurants,
      entity: "restaurant"
    }), {
      restaurantAttributes: a
    } = X(), y = [{
      header: () => t("portalshell.customAttributes.form.key"),
      accessorKey: "key",
      enableSorting: !1
    }, {
      header: () => t("portalshell.customAttributes.form.value"),
      accessorKey: "values",
      enableSorting: !1,
      cell: (f) => {
        const s = f.row.original, u = s.values;
        return G(Q.FmSelect, {
          modelValue: s.value,
          placeholder: t("portalshell.customAttributes.form.valuePlaceholder"),
          items: u.map((l) => ({
            label: l,
            value: l
          })),
          clearable: !0,
          searchable: !0,
          "onUpdate:modelValue": (l) => s.value = l
        });
      }
    }], m = n;
    function b(f) {
      return f.reduce((s, u) => (u.value != null && (s[u.key] = u.value), s), {});
    }
    const h = () => {
      const f = r.value.filter((l) => l.value != null), s = a.value.filter((l) => l.value != null), u = {
        restaurantCustomAttributes: b(f),
        restaurantAttributes: b(s)
      };
      m("confirm", u), C();
    }, p = A(!1);
    function w() {
      var u, l;
      p.value = !0;
      const f = ((u = o.currentRestaurantAttrParams) == null ? void 0 : u.restaurantCustomAttributes) ?? {};
      r.value.forEach((d) => {
        d.value = f[d.key] ?? void 0;
      });
      const s = ((l = o.currentRestaurantAttrParams) == null ? void 0 : l.restaurantAttributes) ?? {};
      a.value.forEach((d) => {
        d.value = s[d.key] ?? void 0;
      });
    }
    function C() {
      p.value = !1;
    }
    return (f, s) => {
      const u = v("FmIcon"), l = v("FmChip"), d = v("FmTable"), V = v("FmSpacer"), F = v("fm-button"), j = v("FmDialog");
      return I(), E(B, null, [g("div", {
        class: "cursor-pointer",
        onClick: w
      }, [c(l, {
        class: T([f.fullWidth ? "w-full justify-between" : ""])
      }, {
        default: _(() => [g("div", Y, S(i(t)("menu.catalog.form.restaurant_attributes_title")), 1), c(u, {
          color: "neutral-gray-400",
          name: "launch",
          size: "sm"
        })]),
        _: 1
      }, 8, ["class"])]), c(j, {
        modelValue: p.value,
        "onUpdate:modelValue": s[0] || (s[0] = (R) => p.value = R),
        overlay: !0,
        "min-width": "min(calc(100% - 48px), 560px)"
      }, {
        "dialog-header": _(() => [g("div", Z, S(i(t)("menu.catalog.form.restaurant_attributes_title")), 1)]),
        "dialog-footer": _(() => [c(V), c(F, {
          label: i(t)("menu.common.actions.confirm"),
          size: "lg",
          type: "submit",
          variant: "primary",
          onClick: h
        }, null, 8, ["label"]), c(F, {
          label: i(t)("menu.common.actions.cancel"),
          size: "lg",
          variant: "tertiary",
          onClick: C
        }, null, 8, ["label"])]),
        default: _(() => [g("div", ee, [c(k, {
          title: i(t)("menu.link_product.rules.restaurant_custom_attributes_filter")
        }, {
          default: _(() => [c(d, {
            "column-defs": y,
            "row-data": i(r),
            "shrink-at": !1,
            "page-size": i(r).length,
            "hide-footer": ""
          }, null, 8, ["row-data", "page-size"])]),
          _: 1
        }, 8, ["title"]), c(k, {
          title: i(t)("menu.link_product.rules.restaurant_filter")
        }, {
          default: _(() => [c(d, {
            "column-defs": y,
            "row-data": i(a),
            "shrink-at": !1,
            "page-size": i(a).length,
            "hide-footer": ""
          }, null, 8, ["row-data", "page-size"])]),
          _: 1
        }, 8, ["title"])])]),
        _: 1
      }, 8, ["modelValue"])], 64);
    };
  }
});
function fe(e) {
  return L() ? ($(e), !0) : !1;
}
function x(e) {
  return typeof e == "function" ? e() : i(e);
}
const pe = typeof window < "u" && typeof document < "u";
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const te = Object.prototype.toString, de = (e) => te.call(e) === "[object Object]", D = () => {
};
function P(e, n) {
  function o(...t) {
    return new Promise((r, a) => {
      Promise.resolve(e(() => n.apply(this, t), { fn: n, thisArg: this, args: t })).then(r).catch(a);
    });
  }
  return o;
}
const z = (e) => e();
function ne(e, n = {}) {
  let o, t, r = D;
  const a = (m) => {
    clearTimeout(m), r(), r = D;
  };
  return (m) => {
    const b = x(e), h = x(n.maxWait);
    return o && a(o), b <= 0 || h !== void 0 && h <= 0 ? (t && (a(t), t = null), Promise.resolve(m())) : new Promise((p, w) => {
      r = n.rejectOnCancel ? w : p, h && !t && (t = setTimeout(() => {
        o && a(o), t = null, p(m());
      }, h)), o = setTimeout(() => {
        t && a(t), t = null, p(m());
      }, b);
    });
  };
}
function oe(e = z) {
  const n = A(!0);
  function o() {
    n.value = !1;
  }
  function t() {
    n.value = !0;
  }
  const r = (...a) => {
    n.value && e(...a);
  };
  return { isActive: N(n), pause: o, resume: t, eventFilter: r };
}
function re(e) {
  return U();
}
function ae(e, n = 200, o = {}) {
  return P(
    ne(n, o),
    e
  );
}
function be(e, n = 200, o = {}) {
  const t = A(e.value), r = ae(() => {
    t.value = e.value;
  }, n, o);
  return O(e, () => r()), t;
}
function se(e, n, o = {}) {
  const {
    eventFilter: t = z,
    ...r
  } = o;
  return O(
    e,
    P(
      t,
      n
    ),
    r
  );
}
function he(e, n, o = {}) {
  const {
    eventFilter: t,
    ...r
  } = o, { eventFilter: a, pause: y, resume: m, isActive: b } = oe(t);
  return { stop: se(
    e,
    n,
    {
      ...r,
      eventFilter: a
    }
  ), pause: y, resume: m, isActive: b };
}
function ve(e, n = !0, o) {
  re() ? K(e, o) : n ? e() : M(e);
}
export {
  me as _,
  ve as a,
  fe as b,
  de as c,
  pe as i,
  D as n,
  be as r,
  x as t,
  he as w
};
