import { useCallback } from 'react';

interface SmoothScrollOptions {
  offset?: number;
  duration?: number;
  behavior?: ScrollBehavior;
}

export function useSmoothScroll() {
  const scrollToElement = useCallback((
    elementOrSelector: HTMLElement | string,
    options: SmoothScrollOptions = {}
  ) => {
    const { offset = 0, behavior = 'smooth' } = options;
    
    const element = typeof elementOrSelector === 'string'
      ? document.querySelector(elementOrSelector) as HTMLElement
      : elementOrSelector;

    if (!element) return;

    const elementPosition = element.getBoundingClientRect().top;
    const offsetPosition = elementPosition + window.pageYOffset - offset;

    window.scrollTo({
      top: offsetPosition,
      behavior,
    });
  }, []);

  const scrollToTop = useCallback((options: SmoothScrollOptions = {}) => {
    const { behavior = 'smooth' } = options;
    window.scrollTo({
      top: 0,
      behavior,
    });
  }, []);

  return { scrollToElement, scrollToTop };
}
