import { defineComponent as g, mergeModels as I, useModel as z, computed as h, ref as _, resolveComponent as n, openBlock as t, createElementBlock as f, normalizeStyle as B, createElementVNode as F, createVNode as N, withCtx as E, createBlock as s, createCommentVNode as k, Fragment as S, renderList as R, unref as r } from "vue";
import { z as u } from "./app-Bpb4394e.js";
import { F as T } from "./FmMultiselectDialog-D-38fV59.js";
const q = { class: "overflow-y-auto h-full pb-8" }, L = /* @__PURE__ */ g({
  __name: "FmFilterableMenuOptions",
  props: /* @__PURE__ */ I({
    modelValue: {},
    maxHeight: {},
    width: {},
    handleItemChange: { type: Function },
    items: {},
    options: {}
  }, {
    search: {},
    searchModifiers: {}
  }),
  emits: ["update:search"],
  setup(i) {
    const y = i, l = z(i, "search"), V = h(
      () => new T(y.items, ["label", "sublabel"], {
        caseSensitive: !1,
        sort: !0
      })
    ), m = h(() => V.value.search(l.value)), d = _();
    return console.log({ stickyRef: d }), (o, a) => {
      const w = n("FmButton"), C = n("FmTextField"), c = n("FmMenuItem");
      return t(), f("div", {
        class: "relative",
        style: B({ width: o.width })
      }, [
        F("div", {
          class: "sticky top-0 bg-white mb-8",
          ref_key: "stickyRef",
          ref: d
        }, [
          N(C, {
            modelValue: l.value,
            "onUpdate:modelValue": a[1] || (a[1] = (e) => l.value = e),
            placeholder: "Filter options"
          }, {
            append: E(() => [
              l.value ? (t(), s(w, {
                key: 0,
                variant: "tertiary",
                "prepend-icon": "close",
                onClick: a[0] || (a[0] = (e) => l.value = "")
              })) : k("", !0)
            ]),
            _: 1
          }, 8, ["modelValue"])
        ], 512),
        F("div", q, [
          (t(!0), f(S, null, R(m.value, (e, M) => (t(), s(c, {
            key: M,
            label: e.label,
            sublabel: e.sublabel,
            "model-value": r(u)(o.modelValue, e.value),
            onClick: () => o.handleItemChange(r(u)(o.modelValue, e.value), e),
            onVnodeMounted: (v) => {
              var p, b;
              return r(u)(o.modelValue, e.value) && ((p = v.el) == null || p.scrollIntoView({ behavior: "instant", block: "end" }), (b = v.el) == null || b.scrollIntoView({ behavior: "smooth", block: "center" })), void 0;
            }
          }, null, 8, ["label", "sublabel", "model-value", "onClick", "onVnodeMounted"]))), 128)),
          m.value.length ? k("", !0) : (t(), s(c, {
            key: 0,
            disabled: "",
            label: "No options available"
          }))
        ])
      ], 4);
    };
  }
});
export {
  L as _
};
