"use client";

import type { ReactNode } from "react";
import { ReactLenis } from "lenis/react";
import { useReducedMotionSafe } from "@/components/motion/use-reduced-motion-safe";

/**
 * Wraps the whole app in Lenis's smoothed scroll. `root` makes it drive the
 * window's real scroll position (not a virtualized wrapper div), so native
 * behaviors that read window.scrollY — the navbar's scroll-blur listener,
 * the sticky-scroll Hero/About reveal on the homepage — keep working as-is.
 *
 * Subscribed (not just checked once) so it also turns off live if the user
 * toggles OS-level reduced-motion while the page is open.
 */
export function SmoothScrollProvider({ children }: { children: ReactNode }) {
  const reduced = useReducedMotionSafe();

  if (reduced) {
    return <>{children}</>;
  }

  return <ReactLenis root>{children}</ReactLenis>;
}
