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


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


	return (
		<svg
			width={width}
			height={height}
			viewBox="0 0 24 24"
			xmlns="http://www.w3.org/2000/svg"
		>
			<rect
				x="1"
				y="4"
				width="6"
				height="14"
				opacity="1"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					id={`rectangle1_${id}`}
					begin={`0;rectangle3_${id}.end-${animationDuration / 3}s`}
					attributeName="y"
					dur={animationDuration}
					values="1;5"
					fill="freeze"
				/>
				<animate
					begin={`0;rectangle3_${id}.end-${animationDuration / 3}s`}
					attributeName="height"
					dur={animationDuration}
					values="22;14"
					fill="freeze"
				/>
				<animate
					begin={`0;rectangle3_${id}.end-${animationDuration / 3}s`}
					attributeName="opacity"
					dur={animationDuration}
					values="1;.2"
					fill="freeze"
				/>
			</rect>
			<rect
				x="9"
				y="4"
				width="6"
				height="14"
				opacity=".4"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 5}s`}
					attributeName="y"
					dur={animationDuration}
					values="1;5"
					fill="freeze"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 5}s`}
					attributeName="height"
					dur={animationDuration}
					values="22;14"
					fill="freeze"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 5}s`}
					attributeName="opacity"
					dur={animationDuration}
					values="1;.2"
					fill="freeze"
				/>
			</rect>
			<rect
				x="17"
				y="4"
				width="6"
				height="14"
				opacity=".3"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					id={`rectangle3_${id}`}
					begin={`rectangle1_${id}.begin+${animationDuration * 2 / 5}s`}
					attributeName="y"
					dur={animationDuration}
					values="1;5"
					fill="freeze"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration * 2 / 5}s`}
					attributeName="height"
					dur={animationDuration}
					values="22;14"
					fill="freeze"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration * 2 / 5}s`}
					attributeName="opacity"
					dur={animationDuration}
					values="1;.2"
					fill="freeze"
				/>
			</rect>
		</svg>
	);
}
