<template>
	<view class="skeleton-box">
		<view v-if="loading" class="skeleton">
			<div class="spinner">
				<div></div>
				<div></div>
				<div></div>
				<div></div>
				<div></div>
			</div>
		</view>
		<van-transition v-else name="fade-up">
			<slot></slot>
		</van-transition>
	</view>
</template>

<script>
	export default {
		props: {
			loading: {
				type: Boolean,
				default: true
			},
			list: {
				type: Array,
				default: [1]
			}
		}
	}
</script>

<style lang="scss" scoped>
	.skeleton {
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 50rpx;
		height: 320rpx;
	}

	.led {
		width: 10rpx;
		height: 30rpx;
		border-radius: 10rpx;
		top: 50rpx;
		position: absolute;
		transform: rotate(calc(360deg / var(--all) * var(--i)));
		transform-origin: 0 160rpx;
		animation: loading 2s linear infinite;
		animation-delay: calc(var(--i) * 1s);
		background-color: green;
	}

	@keyframes loading {
		from {
			opacity: 0;
		}

		to {
			opacity: 1;
		}
	}

	.spinner {
		margin: 100px auto;
		width: 50px;
		height: 50px;
		text-align: center;
		font-size: 10px;
	}

	.spinner>div {
		display: inline-block;
		background-color: rgb(55, 226, 83);
		height: 100%;
		width: 5px;
		margin-right: 1px;
		animation: bytedance 1s infinite;
	}

	.spinner>div:nth-of-type(2) {
		background-color: rgb(41, 124, 54);
		animation-delay: -0.9s;
	}

	.spinner>div:nth-child(3) {
		background-color: rgb(45, 173, 22);
		animation-delay: -0.8s;
	}

	.spinner>div:nth-child(4) {
		background-color: rgb(154, 173, 153);
		animation-delay: -0.7s;
	}

	.spinner>div:nth-child(5) {
		background-color: rgb(22, 240, 77);
		animation-delay: -0.6s;
	}

	@keyframes bytedance {

		0%,
		40%,
		100% {
			transform: scaleY(0.4);
		}

		20% {
			transform: scaleY(1);
		}
	}
</style>
