"use client";
import { useRef } from "react";
import { useScroll, useTransform, useSpring } from "framer-motion";

export function useParallax(distance = 40, damping = 28) {
  const ref = useRef<HTMLDivElement>(null);
  const { scrollYProgress } = useScroll({
    target: ref,
    offset: ["start end", "end start"],
  });
  const raw = useTransform(scrollYProgress, [0, 1], [-distance, distance]);
  const y   = useSpring(raw, { stiffness: 120, damping });
  return { ref, y, scrollYProgress };
}
