import type { LoadingDotsProps } from "$/types/LoadingTypes";
import { usePrefersReducedMotion } from "$/util/AccessibilityUtil";


export default function CircleRotatingDots({
	size,
	width,
	height,
	className,
	animationDuration = 1500,
	color,
	stroke,
	fill,
	ariaLabel = "Loading"
}: Readonly<LoadingDotsProps>){
	//https://github.com/n3r4zzurr0/svg-spinners/blob/main/svg-smil/8-dots-rotate.svg
	const reducedMotion = usePrefersReducedMotion();
	const dur = reducedMotion ? animationDuration / 100 : animationDuration / 1000;


	return (
		<svg
			width={size ?? width}
			height={size ?? height}
			role="status"
			aria-live="polite"
			aria-label={ariaLabel}
			viewBox="0 0 24 24"
			xmlns="http://www.w3.org/2000/svg"
		>
			<g>
				<circle
					cx="3"
					cy="12"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<circle
					cx="21"
					cy="12"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<circle
					cx="12"
					cy="21"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<circle
					cx="12"
					cy="3"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<circle
					cx="5.64"
					cy="5.64"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<circle
					cx="18.36"
					cy="18.36"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<circle
					cx="5.64"
					cy="18.36"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<circle
					cx="18.36"
					cy="5.64"
					r="2"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<animateTransform
					attributeName="transform"
					type="rotate"
					dur={dur}
					values="0 12 12;360 12 12"
					repeatCount="indefinite"
				/>
			</g>
		</svg>
);
}
