import type { ReactNode } from "react";
import { cn } from "@/pages/app/components/ui";

type AutoMarqueeProps = {
  children: ReactNode;
  /** seconds for one full loop — larger means slower */
  speed?: number;
  gapClassName?: string;
  className?: string;
};

/**
 * Continuous horizontal auto-scroll row (like the news ticker).
 * Children are rendered twice so the -50% translate loops seamlessly.
 * Pauses on hover and for users who prefer reduced motion.
 */
export default function AutoMarquee({
  children,
  speed = 48,
  gapClassName = "gap-3",
  className,
}: AutoMarqueeProps) {
  return (
    <div className={cn("overflow-hidden", className)}>
      <div
        className={cn(
          "flex w-max hover:[animation-play-state:paused] motion-reduce:[animation-play-state:paused]",
          gapClassName,
        )}
        style={{ animation: `marquee ${speed}s linear infinite` }}
      >
        <div className={cn("flex shrink-0", gapClassName)}>{children}</div>
        <div className={cn("flex shrink-0", gapClassName)} aria-hidden="true">
          {children}
        </div>
      </div>
    </div>
  );
}