import { defineComponent as O, inject as b, ref as y, computed as R, openBlock as f, createBlock as k, withCtx as l, createElementVNode as d, unref as t, renderSlot as W, createVNode as p, Transition as j, createElementBlock as J, createCommentVNode as x, createTextVNode as m, toDisplayString as w } from "vue";
import { throttle as z } from "es-toolkit";
import { t as C } from "./locale.js";
import D from "./Button.js";
import "./Module.keys-DcqBbvvT.js";
import "es-toolkit/compat";
import { D as F } from "./DataView.keys-aSOnA4AD.js";
import { D as G } from "./DataViewFilters.keys-BLu07FiP.js";
import $ from "./Dropdown.js";
import q from "./FilterChip.js";
const H = { class: "flex h-full flex-col rounded" }, K = { class: "flex-1 overflow-hidden rounded-t" }, M = {
  key: 0,
  class: "pointer-events-none absolute inset-x-0 bottom-0 z-10 h-[20px] bg-scroll-shadow"
}, P = { class: "flex shrink-0 justify-end gap-6 rounded-b border border-solid border-x-ice-100 border-b-ice-100 border-t-ice-200 bg-ice-100 p-3.5" }, ne = /* @__PURE__ */ O({
  __name: "FilterDropdown",
  props: {
    label: {},
    group: {},
    onApply: { type: Function, default: () => {
    } }
  },
  emits: ["reset", "dismiss"],
  setup(T, { emit: I }) {
    const s = T, c = I, { isLoading: h } = b(F.key, F.defaults), i = b(G.key);
    if (!(i != null && i.useFiltersInstance))
      throw new Error(
        "FilterDropdown must be used within a <DataViewFilters> that receives an instance of useFilters()."
      );
    const { applyFilters: E, resetFilterGroup: S, activeFiltersCounts: v, undoWorkingFilters: _ } = i.useFiltersInstance, n = y(), u = R(() => {
      var e;
      return (e = n.value) == null ? void 0 : e.isActive;
    });
    function A() {
      var o;
      const e = u.value;
      (o = n.value) == null || o.toggle(), e && (_(), c("dismiss"));
    }
    function N() {
      var e;
      S(s.group), c("reset"), (e = n.value) == null || e.dismiss();
    }
    async function V() {
      var o, a;
      const { preventDismiss: e } = await ((o = s.onApply) == null ? void 0 : o.call(s)) || E() || {};
      e || (a = n.value) == null || a.dismiss();
    }
    function B() {
      _(), c("dismiss");
    }
    const r = y(!1), g = z((e) => {
      e.target && (e.target.scrollTop > 0 ? r.value = !0 : r.value = !1);
    }, 500);
    function L() {
      setTimeout(() => {
        r.value = !1;
      }, 2e3);
    }
    return (e, o) => (f(), k($, {
      ref_key: "dropdownRef",
      ref: n,
      align: "left",
      class: "stash-filter-dropdown",
      "data-test": "stash-filter-dropdown",
      "fluid-content": "",
      "close-manually": "",
      "content-class": "w-full max-w-[600px] h-[400px]",
      offset: { y: 6 },
      onDismiss: B
    }, {
      toggle: l(() => [
        p(q, {
          class: "rounded-full",
          "has-dropdown": "",
          "is-dropdown-open": u.value,
          "filter-count": t(v)[s.group],
          "is-selected": u.value,
          onClick: A
        }, {
          default: l(() => [
            m(w(s.label), 1)
          ]),
          _: 1
        }, 8, ["is-dropdown-open", "filter-count", "is-selected"])
      ]),
      default: l(() => [
        d("div", H, [
          d("div", K, [
            d("div", {
              class: "relative h-full overflow-auto p-6",
              onScroll: o[0] || (o[0] = //@ts-ignore
              (...a) => t(g) && t(g)(...a)),
              onScrollend: L
            }, [
              W(e.$slots, "default")
            ], 32),
            p(j, { name: "fade" }, {
              default: l(() => [
                r.value ? (f(), J("div", M)) : x("", !0)
              ]),
              _: 1
            })
          ]),
          d("footer", P, [
            t(v)[s.group] ? (f(), k(D, {
              key: 0,
              secondary: "",
              class: "min-w-[100px]",
              disabled: t(h),
              onClick: N
            }, {
              default: l(() => [
                m(w(t(C)("ll.reset")), 1)
              ]),
              _: 1
            }, 8, ["disabled"])) : x("", !0),
            p(D, {
              class: "min-w-[100px]",
              disabled: t(h),
              onClick: V
            }, {
              default: l(() => [
                m(w(t(C)("ll.apply")), 1)
              ]),
              _: 1
            }, 8, ["disabled"])
          ])
        ])
      ]),
      _: 3
    }, 512));
  }
});
export {
  ne as default
};
//# sourceMappingURL=FilterDropdown.js.map
