import { isElementInViewport } from './dom';

/**
 * Scroll element into view if not already visible.
 */
export function scrollToElement(
  element: HTMLElement,
  behavior: ScrollBehavior = 'smooth'
): void {
  if (isElementInViewport(element)) return;

  element.scrollIntoView({
    behavior,
    block: 'center',
    inline: 'center',
  });
}

/**
 * Wait for scroll to complete (approximate).
 */
export function waitForScroll(duration = 300): Promise<void> {
  return new Promise((resolve) => setTimeout(resolve, duration));
}
