import { jsx as O } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useMemo as C, useCallback as j, useRef as g, useEffect as u } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useTimeRangeSelection as w } from "./useTimeRangeSelection.js";
import x from "../../../FormFields/Select/Select.js";
const y = ({
  ["aria-label"]: p,
  calendarRef: e,
  onTimeRangeSelected: i,
  timestamp: n,
  ...T
}) => {
  const { customSelection: l, from: r, onSelection: a, options: m, selectedOption: s, to: o } = w(T), S = C(() => Object.freeze(m.map((t) => ({ id: t, name: t }))), [m]), b = j(({ target: t }) => a(t?.value), [a]), c = g(!0), f = g(n);
  return u(() => {
    e?.current && r && o && (c.current = !0, e.current.from = new Date(r), e.current.to = new Date(o));
  }, [e, r, o]), u(() => {
    if (f.current !== n) {
      f.current = n;
      const t = e?.current?.from?.getTime(), h = e?.current?.to?.getTime();
      if (t === r && h === o) {
        c.current = !1;
        return;
      }
      c.current ? c.current = !1 : l();
    }
  }, [e, l, r, n, o]), u(() => {
    s && i?.(s);
  }, [s, i]), /* @__PURE__ */ O(
    x,
    {
      setToTargetWidth: !0,
      items: S,
      filterable: !1,
      multiSelect: !1,
      onChange: b,
      selected: s,
      "aria-label": p
    }
  );
};
export {
  y as default
};
