export const useScrollToTop = () => {
  const scrollToTop = (smooth = true, duration = 300) => {
    if (smooth && window.requestAnimationFrame) {
      // Custom smooth scroll
      const start = window.pageYOffset;
      const startTime = performance.now();

      const animateScroll = (currentTime) => {
        const timeElapsed = currentTime - startTime;
        const progress = Math.min(timeElapsed / duration, 1);
        const ease = 1 - Math.pow(1 - progress, 3);

        window.scrollTo(0, start * (1 - ease));

        if (progress < 1) {
          requestAnimationFrame(animateScroll);
        }
      };

      requestAnimationFrame(animateScroll);
    } else {
      // Fallback to CSS smooth or instant
      window.scrollTo({
        top: 0,
        left: 0,
        behavior: smooth ? "smooth" : "auto",
      });
    }
  };

  return { scrollToTop };
};
