import type { LoadingPulseProps } from "$/types/LoadingTypes";
import { usePrefersReducedMotion } from "$/util/AccessibilityUtil";
import { useId } from "react";


export default function TripleDrop({
	size,
	width,
	height,
	className,
	animationDuration = 1200,
	color,
	stroke,
	fill,
	ariaLabel = "Loading"
}: Readonly<LoadingPulseProps>){
	//https://github.com/n3r4zzurr0/svg-spinners/blob/main/svg-smil/pulse-3.svg
	const id = useId();
	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"
		>
			<circle
				cx="12"
				cy="12"
				r="0"
				className={className}
				stroke={color ?? stroke}
				fill={color ?? fill}
			>
				<animate
					id={`drop1_${id}`}
					begin={`0;drop3_${id}.begin+${dur / 3}s`}
					attributeName="r"
					calcMode="spline"
					dur={dur}
					values="0;11"
					keySplines=".52,.6,.25,.99"
					fill="freeze"
				/>
				<animate
					begin={`0;drop3_${id}.begin+${dur / 3}s`}
					attributeName="opacity"
					calcMode="spline"
					dur={dur}
					values="1;0"
					keySplines=".52,.6,.25,.99"
					fill="freeze"
				/>
			</circle>
			<circle
				cx="12"
				cy="12"
				r="0"
				className={className}
				stroke={color ?? stroke}
				fill={color ?? fill}
			>
				<animate
					id={`drop2_${id}`}
					begin={`drop1_${id}.begin+${dur / 3}s`}
					attributeName="r"
					calcMode="spline"
					dur={dur}
					values="0;11"
					keySplines=".52,.6,.25,.99"
					fill="freeze"
				/>
				<animate
					begin={`drop1_${id}.begin+${dur / 3}s`}
					attributeName="opacity"
					calcMode="spline"
					dur={dur}
					values="1;0"
					keySplines=".52,.6,.25,.99"
					fill="freeze"
				/>
			</circle>
			<circle
				cx="12"
				cy="12"
				r="0"
				className={className}
				stroke={color ?? stroke}
				fill={color ?? fill}
			>
				<animate
					id={`drop3_${id}`}
					begin={`drop1_${id}.begin+${dur * 2 / 3}s`}
					attributeName="r"
					calcMode="spline"
					dur={dur}
					values="0;11"
					keySplines=".52,.6,.25,.99"
					fill="freeze"
				/>
				<animate
					begin={`drop1_${id}.begin+${dur * 2 / 3}s`}
					attributeName="opacity"
					calcMode="spline"
					dur={dur}
					values="1;0"
					keySplines=".52,.6,.25,.99"
					fill="freeze"
				/>
			</circle>
		</svg>
	);
}
