import { jsx as e, jsxs as X } from "react/jsx-runtime";
import { useState as G, useRef as m, useMemo as L, useCallback as U } from "react";
import { COMMAND_VARIANT as F } from "../../../command/constants/index.js";
import { DATE_OPERATOR_TEXT_OVERRIDES as $ } from "../../constants/index.js";
import q from "../../hooks/useDataTableStaticContext.js";
import J from "./hooks/useDataTableFilterState.js";
import K from "./hooks/useFilterDisplayWidth.js";
import Q from "./hooks/useDataTableFilterHandlers.js";
import Y from "./hooks/useFilterOperatorOptions.js";
import Z from "../data-table-date-filter-input/DataTableDateFilterInput.js";
import { Popover as ee, PopoverTrigger as te, PopoverContent as re } from "../../../popover/PopoverPrimitive.js";
import oe from "../data-table-filter-display/DataTableFilterDisplay.js";
import c from "../../../button/Button.js";
import ne from "../../../icon/Icon.js";
import le from "../../../command/Command.js";
import S from "../../../box/Box.js";
import { FilterValueType as x } from "../../types/FilterValueType.js";
import { c as ae } from "../../../../index-BtlgVD4m.js";
const Se = ({
  onChange: R,
  value: E,
  operator: N,
  mode: V,
  options: u,
  columnKey: f,
  valueType: r
}) => {
  var A;
  const [d, y] = G(!1), a = m(null), h = m(null), C = m(null), { columns: I } = q(), {
    selectedOperator: M,
    setSelectedOperator: P,
    selectedValue: k,
    setSelectedValue: B,
    searchText: g,
    setSearchText: j,
    internalValue: o,
    internalOperator: n,
    isFilterActive: O,
    isSingleMode: t
  } = J(E, N, V), w = K(a, M, k), _ = t && r === x.NUMBER, { handleChangeValue: i, handleChangeOperator: s, handleClearFilter: D, handleApplySingleFilter: z } = Q({
    columnKey: f,
    internalOperator: n,
    internalValue: o,
    searchText: g,
    isSingleMode: t,
    popoverContentRef: C,
    popoverTriggerRef: h,
    setSelectedValue: B,
    setSelectedOperator: P,
    onChange: R
  }), T = r === x.DATE, { getOperatorOptions: v, operatorOptions: b } = Y(
    s,
    r,
    T ? $ : void 0
  ), l = (A = I.find((p) => p.key === f)) == null ? void 0 : A.title, H = L(() => [
    {
      heading: "Alle Werte",
      items: u
    }
  ], [u]), W = U(
    (p) => {
      i(p);
    },
    [i]
  );
  return l ? T ? /* @__PURE__ */ e(
    Z,
    {
      filterDisplayRef: a,
      columnTitle: l,
      internalOperator: n,
      internalValue: o,
      isFilterActive: !!O,
      operatorOptions: b,
      getOperatorOptions: v,
      valueType: r,
      onOperatorChange: s,
      onApply: W,
      onClear: D
    }
  ) : /* @__PURE__ */ e("div", { className: "flex", children: /* @__PURE__ */ X(ee, { open: d, onOpenChange: y, children: [
    /* @__PURE__ */ e(te, { asChild: !0, children: O ? /* @__PURE__ */ e("div", { ref: h, children: /* @__PURE__ */ e(
      oe,
      {
        ref: a,
        getOperatorOptions: v,
        columnTitle: l,
        selectedOperator: n,
        selectedValue: o,
        valueType: r
      }
    ) }) : /* @__PURE__ */ e(
      c,
      {
        label: l,
        variant: "outline",
        size: "sm",
        icon: /* @__PURE__ */ e(ne, { name: "ChevronDown", className: ae("transition-transform", d ? "rotate-180" : ""), size: 16 }),
        iconPosition: "right"
      }
    ) }),
    /* @__PURE__ */ e(re, { style: { width: `${Math.max(w, 240)}px` }, className: "p-0", align: "start", ref: C, children: /* @__PURE__ */ e(
      le,
      {
        placeholder: "Suche Filtername",
        isPopover: !0,
        groups: H,
        variant: t ? F.SIMPLE : F.CHECKBOX,
        value: t ? g : o,
        inputType: _ ? "number" : void 0,
        selectionConfig: {
          enabled: !0,
          options: b,
          value: n,
          onSelect: s
        },
        hideContent: t,
        footer: t ? /* @__PURE__ */ e(S, { className: "flex justify-center", children: /* @__PURE__ */ e(c, { label: "Aktualisieren", variant: "ghost", size: "sm", onClick: z }) }) : o.length === 0 ? null : /* @__PURE__ */ e(S, { className: "flex justify-center", children: /* @__PURE__ */ e(c, { label: "Auswahl aufheben", variant: "ghost", onClick: D }) }),
        onItemSelect: i,
        onValueChange: j
      }
    ) })
  ] }) }) : null;
};
export {
  Se as default
};
//# sourceMappingURL=DataTableFilterInput.js.map
