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


export default function CircleBars({
	size,
	width,
	height,
	className,
	animationDuration = 750,
	color,
	stroke,
	fill,
	ariaLabel = "Loading"
}: Readonly<LoadingBarsProps>){
	//https://github.com/n3r4zzurr0/svg-spinners/blob/main/svg-smil/bars-rotate-fade.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>
				<rect
					x="11"
					y="1"
					width="2"
					height="5"
					opacity=".14"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<rect
					x="11"
					y="1"
					width="2"
					height="5"
					transform="rotate(30 12 12)"
					opacity=".29"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<rect
					x="11"
					y="1"
					width="2"
					height="5"
					transform="rotate(60 12 12)"
					opacity=".43"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<rect
					x="11"
					y="1"
					width="2"
					height="5"
					transform="rotate(90 12 12)"
					opacity=".57"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<rect
					x="11"
					y="1"
					width="2"
					height="5"
					transform="rotate(120 12 12)"
					opacity=".71"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<rect
					x="11"
					y="1"
					width="2"
					height="5"
					transform="rotate(150 12 12)"
					opacity=".86"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<rect
					x="11"
					y="1"
					width="2"
					height="5"
					transform="rotate(180 12 12)"
					className={className}
					stroke={color ?? stroke}
					fill={color ?? fill}
				/>
				<animateTransform
					attributeName="transform"
					type="rotate"
					calcMode="discrete"
					dur={dur}
					values="0 12 12;30 12 12;60 12 12;90 12 12;120 12 12;150 12 12;180 12 12;210 12 12;240 12 12;270 12 12;300 12 12;330 12 12"
					repeatCount="indefinite"
				/>
			</g>
		</svg>
	);
}