"use client";

import { useEffect } from "react";

/** Prevent mouse-wheel from changing focused number inputs. */
export function DisableNumberInputWheel() {
  useEffect(() => {
    const onWheel = (e: WheelEvent) => {
      const el = e.target;
      if (
        el instanceof HTMLInputElement &&
        el.type === "number" &&
        document.activeElement === el
      ) {
        e.preventDefault();
        el.blur();
      }
    };
    document.addEventListener("wheel", onWheel, { passive: false });
    return () => document.removeEventListener("wheel", onWheel);
  }, []);

  return null;
}
