import type { LoadingDotsProps } from "$/types/Loading";


export default function SwellingDots({
	width,
	height,
	className,
	animationDuration = 0.75,
	stroke,
	fill
}: LoadingDotsProps){
	//https://github.com/n3r4zzurr0/svg-spinners/blob/main/svg-smil/3-dots-scale.svg
	const id = crypto.randomUUID().replaceAll("-", "");


	return (
		<svg
			width={width}
			height={height}
			viewBox="0 0 24 24"
			xmlns="http://www.w3.org/2000/svg"
		>
			<circle
				cx="4"
				cy="12"
				r="3"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					id={`firstDot_${id}`}
					begin={`0;lastDot_${id}.end-${animationDuration / 3}s`}
					attributeName="r"
					dur={animationDuration}
					values="3;.2;3"
				/>
			</circle>
			<circle
				cx="12"
				cy="12"
				r="3"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					begin={`firstDot_${id}.end-${animationDuration * 4 / 5}s`}
					attributeName="r"
					dur={animationDuration}
					values="3;.2;3"
				/>
			</circle>
			<circle
				cx="20"
				cy="12"
				r="3"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					id={`lastDot_${id}`}
					begin={`firstDot_${id}.end-${animationDuration * 2 / 3}s`}
					attributeName="r"
					dur={animationDuration}
					values="3;.2;3"
				/>
			</circle>
		</svg>
	);
}
