<script>
	/**
	 * @typedef {Object} Props
	 * @property {boolean} [theme]
	 * @property {boolean} [inverse]
	 * @property {string} [size]
	 * @property {any} [customColor]
	 * @property {number} [speed]
	 */

	/** @type {Props} */
	let { theme = false, inverse = false, size = 'w-8 h-8', customColor = [], speed = $bindable(1) } = $props();

	const colorClass = () => {
		if (inverse) {
			return theme ? ' bg-dark dark:bg-primary' : ' bg-white dark:bg-black';
		} else {
			return theme ? ' bg-primary dark:bg-dark' : ' bg-black dark:bg-white';
		}
	};
</script>

<div class="{size} m-auto relative flex items-center -rotate-90">
	{#each [1, 0.9, 0.6, 0.4] as item, i}
		<div
			class="dot absolute left-0 h-full w-full flex flex-col items-center"
			style="animation-duration: {1.6 / speed}s;animation-delay: {(1.6 / speed) * -(0.4 - i * 0.09)}s;"
		>
			<div
				class="w-1/4 h-1/4 rounded-full{colorClass()}"
				style="background-color: {customColor[0]};opacity: {item};transform: scale({1 - 0.1 * i});"
			></div>
		</div>
	{/each}
</div>

<style>
	.dot {
		animation: swing linear infinite;
	}

	@keyframes swing {
		0% {
			transform: rotate(0deg);
		}

		15% {
			transform: rotate(0deg);
		}

		50% {
			transform: rotate(180deg);
		}

		65% {
			transform: rotate(180deg);
		}

		100% {
			transform: rotate(0deg);
		}
	}
</style>
