import { jsx as i } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import b from "classnames";
import { ButtonVariant as c } from "../Button/types.js";
import { useState as C, useEffect as B, useMemo as h } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useResponsiveContainer as x, containerQueries as F } from "../../../hooks/useResponsiveContainer.js";
/* empty css               */
import I from "../../../hooks/useUniqueId.js";
import m from "../../../core/Context/preact/useCoreContext.js";
import d from "../Button/Button.js";
import { Icon as S } from "../Icon/Icon.js";
import { isFunction as E } from "../../../utils/value/is.js";
const s = "adyen-pe-filter-bar-mobile-switch", L = () => {
  const e = x(F.down.xs), [t, o] = C(!e), r = `filters-${I()}`;
  return B(() => {
    o(!e);
  }, [e]), { filterBarElementId: r, isMobileContainer: e, showingFilters: t, setShowingFilters: o };
}, k = ({
  ariaLabelKey: e,
  filterBarElementId: t,
  isMobileContainer: o,
  showingFilters: r,
  setShowingFilters: n
}) => {
  const { i18n: a } = m(), f = h(() => a.get(e ?? "common.filters.mobile.label"), [a, e]), l = !E(n), u = !l && !!r;
  return o ? /* @__PURE__ */ i("div", { className: s, children: /* @__PURE__ */ i(
    d,
    {
      iconButton: !0,
      className: `${s}__button`,
      disabled: l,
      "aria-label": f,
      "aria-expanded": u,
      "aria-controls": t,
      onClick: () => n?.(!r),
      variant: c.SECONDARY,
      children: /* @__PURE__ */ i(S, { name: r ? "cross" : "filter" })
    }
  ) }) : null;
}, O = (e) => {
  const { i18n: t } = m();
  return e.showingFilters ? /* @__PURE__ */ i(
    "div",
    {
      role: "group",
      "data-testid": "filter-bar",
      "aria-label": t.get(e.ariaLabelKey ?? "common.filters.label"),
      className: b("adyen-pe-filter-bar", { "adyen-pe-filter-bar--mobile": e.isMobileContainer }),
      id: e.filterBarElementId,
      children: [
        e.children,
        e.canResetFilters && !!e.resetFilters && /* @__PURE__ */ i(d, { variant: c.TERTIARY, onClick: e.resetFilters, children: t.get("common.filters.controls.resetAll.label") })
      ]
    }
  ) : null;
};
export {
  O as FilterBar,
  k as FilterBarMobileSwitch,
  O as default,
  L as useFilterBarState
};
