import { jsx as t, jsxs as A } from "react/jsx-runtime";
import { useState as p, useRef as I, useEffect as j, useCallback as i, useMemo as E } from "react";
import W from "../../deprecated/advanced-filter/types/FilterConditionOperator.js";
import v from "../../../button/Button.js";
import w from "../../../box/Box.js";
import q from "../../../date-range-picker/DateRangePicker.js";
import z from "../../../select/Select.js";
import G from "../../../date-picker/DatePicker.js";
const X = ({
  columnTitle: C,
  operator: g,
  value: n,
  operatorOptions: D,
  onOperatorChange: R,
  onApply: h,
  onClear: k,
  onClose: l,
  triggerContent: x
}) => {
  const o = g === W.In, [d, f] = p(!1), r = I(void 0), [B, a] = p(void 0), s = I(void 0), [M, c] = p(void 0);
  j(() => {
    r.current = void 0, s.current = void 0, a(void 0), c(void 0);
  }, [o]), j(() => {
    if (!d) {
      if (!(n != null && n.length)) {
        r.current = void 0, s.current = void 0, a(void 0), c(void 0);
        return;
      }
      if (o) {
        const e = n[0], m = n[1], u = { from: e, to: m };
        s.current = u, c(u);
      } else {
        const e = n[0];
        r.current = e, a(e);
      }
    }
  }, [n, o, d]);
  const N = i((e) => {
    r.current = e, a(e);
  }, []), y = i((e) => {
    s.current = e, c(e);
  }, []), O = i(() => {
    if (o) {
      const e = s.current, m = [(e == null ? void 0 : e.from) ?? null, (e == null ? void 0 : e.to) ?? null].filter((u) => u !== null);
      h(m);
    } else {
      const e = r.current;
      h(e ? [e] : []);
    }
    f(!1), l();
  }, [o, h, l]), b = i(() => {
    r.current = void 0, s.current = void 0, a(void 0), c(void 0), f(!1), k(), l();
  }, [k, l]), P = E(
    () => x ?? /* @__PURE__ */ t(v, { label: C, variant: "outline", size: "sm", icon: "ChevronDown", iconPosition: "right", fullWidth: !0 }),
    [x, C]
  ), S = i(
    ({ onApply: e }) => /* @__PURE__ */ A(w, { className: "flex w-full items-center justify-end gap-[var(--spacing-4)]", children: [
      /* @__PURE__ */ t(v, { label: "Auswahl aufheben", variant: "outline", size: "sm", onClick: b }),
      /* @__PURE__ */ t(
        v,
        {
          label: "Filtern",
          size: "sm",
          onClick: () => {
            e(), O();
          }
        }
      )
    ] }),
    [O, b]
  ), F = i(
    (e) => {
      R(e);
    },
    [R]
  );
  return /* @__PURE__ */ t(w, { className: "flex flex-col gap-[var(--spacing-2)]", children: o ? /* @__PURE__ */ t(
    q,
    {
      header: /* @__PURE__ */ t(z, { options: D, value: g, onChange: F, isPortal: !1 }),
      value: M,
      onChange: y,
      hasInput: !0,
      triggerContent: P,
      footer: S,
      isOpen: d,
      onOpenChange: f
    }
  ) : /* @__PURE__ */ t(
    G,
    {
      header: /* @__PURE__ */ t(z, { options: D, value: g, onChange: F, isPortal: !1 }),
      value: B,
      onChange: N,
      hasInput: !0,
      closeOnSelect: !1,
      triggerContent: P,
      footer: S,
      isOpen: d,
      onOpenChange: f
    }
  ) });
};
export {
  X as default
};
//# sourceMappingURL=DataTableDateFilterContent.js.map
