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


export default function PulsingBlocks({
	width,
	height,
	className,
	animationDuration = 0.6,
	stroke,
	fill
}: LoadingBlocksProps){
	//https://github.com/n3r4zzurr0/svg-spinners/blob/main/svg-smil/blocks-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"
		>
			<rect
				x="1.5"
				y="1.5"
				rx="1"
				width="9"
				height="9"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					id={`rectangle1_${id}`}
					begin={`0;rectangle4_${id}.end+${animationDuration / 4}s`}
					attributeName="x"
					dur={animationDuration}
					values="1.5;.5;1.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`0;rectangle4_${id}.end+${animationDuration / 4}s`}
					attributeName="y"
					dur={animationDuration}
					values="1.5;.5;1.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`0;rectangle4_${id}.end+${animationDuration / 4}s`}
					attributeName="width"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`0;rectangle4_${id}.end+${animationDuration / 4}s`}
					attributeName="height"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
			</rect>
			<rect
				x="13.5"
				y="1.5"
				rx="1"
				width="9"
				height="9"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 4}s`}
					attributeName="x"
					dur={animationDuration}
					values="13.5;12.5;13.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 4}s`}
					attributeName="y"
					dur={animationDuration}
					values="1.5;.5;1.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 4}s`}
					attributeName="width"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 4}s`}
					attributeName="height"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
			</rect>
			<rect
				x="13.5"
				y="13.5"
				rx="1"
				width="9"
				height="9"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 2}s`}
					attributeName="x"
					dur={animationDuration}
					values="13.5;12.5;13.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 2}s`}
					attributeName="y"
					dur={animationDuration}
					values="13.5;12.5;13.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 2}s`}
					attributeName="width"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration / 2}s`}
					attributeName="height"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
			</rect>
			<rect
				x="1.5"
				y="13.5"
				rx="1"
				width="9"
				height="9"
				className={className}
				stroke={stroke}
				fill={fill}
			>
				<animate
					id={`rectangle4_${id}`}
					begin={`rectangle1_${id}.begin+${animationDuration * 3 / 4}s`}
					attributeName="x"
					dur={animationDuration}
					values="1.5;.5;1.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration * 3 / 4}s`}
					attributeName="y"
					dur={animationDuration}
					values="13.5;12.5;13.5"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration * 3 / 4}s`}
					attributeName="width"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
				<animate
					begin={`rectangle1_${id}.begin+${animationDuration * 3 / 4}s`}
					attributeName="height"
					dur={animationDuration}
					values="9;11;9"
					keyTimes="0;.2;1"
				/>
			</rect>
		</svg>
	);
}
