<template>
	<view class="demo-block">
		<text class="demo-block__title-text ultra">Transition 动画</text>
		<text class="demo-block__desc-text">使元素从一种样式逐渐变化为另一种样式的效果。</text>
		<view class="demo-block__body">
			<view class="demo-block">
				<text class="demo-block__title-text large">基础使用</text>
				<view class="demo-block__body">
					<l-transition :visible="true" :appear="true" name="fade-up">
						<view class="box1">内容</view>
					</l-transition>
				</view>
			</view>

			<view class="demo-block">
				<text class="demo-block__title-text large">动画类型</text>
				<view class="demo-block__body">
					<button style="margin-bottom:20rpx"  @click="onClick('fade')">Fade</button>
					<button style="margin-bottom:20rpx"  @click="onClick('fade-up')">Fade Up</button>
					<button style="margin-bottom:20rpx"  @click="onClick('fade-down')">Fade Down</button>
					<button style="margin-bottom:20rpx"  @click="onClick('fade-left')">Fade Left</button>
					<button style="margin-bottom:20rpx"  @click="onClick('fade-right')">Fade Right</button>
					<button style="margin-bottom:20rpx"  @click="onClick('slide-up')">Slide Up</button>
					<button style="margin-bottom:20rpx"  @click="onClick('slide-down')">Slide Down</button>
					<button style="margin-bottom:20rpx"  @click="onClick('slide-left')">Slide Left</button>
					<button style="margin-bottom:20rpx"  @click="onClick('slide-right')">slide right</button>
					<l-transition :visible="visible" :destoryOnClose="true" :name="name" class="box">
						<view class="content">内容1</view>
					</l-transition>
				</view>
			</view>
			<view class="demo-block">
				<text class="demo-block__title-text large">高级用法</text>
				<view class="demo-block__body">
					<l-transition 
						:visible="show" 
						name="" 
						:duration="1000"
						enter-class="custom-enter-class"
						enter-active-class="custom-enter-active-class"
						leave-active-class="custom-leave-active-class"
						leave-to-class="custom-leave-to-class"
						class="box">
						<view class="content">内容</view>
					</l-transition>
					
					<button @click="toggle">切换</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script lang="uts" setup>
	let timer : number = -1;
	const visible = ref(false);
	const show = ref(false);
	const name = ref('');
	
	const toggle = () => {
		show.value = !show.value
	}
	
	const onClick = (v : string) => {
		if (v.length > 0) {
			clearTimeout(timer)
			name.value = v;
			visible.value = true;
			timer = setTimeout(() => {
				visible.value = false;
			}, 600)
		}
	}
</script>
<style lang="scss">
	$card-bg-color: var(--doc-card-bg-color, white);
	// $page-bg-color: var(--doc-page-bg-color, #f5f5f5);
	$title-color: var(--doc-title-color, #000000E6);
	$summary-color: var(--doc-summary-color, #00000099);
	
	.custom-enter-active-class,
	.custom-leave-active-class {
	  transition-property: background-color, transform, opacity;
	}
	
	.custom-enter-class,
	.custom-leave-to-class {
	  background-color: red;
	  transform-origin: center;
	  opacity: 1;
	  transform: rotate(-360deg) translate(-100%, -100%);
	}
	.box1{
		width: 300rpx;
		height: 300rpx;
		background-color: #ffb400;
		justify-content: center;
		align-items: center;
	}
	.box {
		position: fixed;
		top: 50%;
		left: 50%;
		width: 300rpx;
		height: 300rpx;
		margin: -150rpx 0 0 -150rpx;
		background-color: #ffb400;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 10;
	}


	.demo-block {
		margin: 32px 20px 0;
		overflow: visible;

		&__title {
			margin: 0;
			margin-top: 8px;

			&-text {
				color: $summary-color;
				font-weight: 400;
				font-size: 14px;
				line-height: 16px;

				&.large {
					color: $title-color;
					font-size: 18px;
					font-weight: 700;
					line-height: 26px;
				}

				&.ultra {
					color: $title-color;
					font-size: 24px;
					font-weight: 700;
					line-height: 32px;
				}
			}
		}

		&__desc-text {
			color: $summary-color;
			margin: 8px 16px 0 0;
			font-size: 14px;
			line-height: 22px;
		}

		&__body {
			margin: 16px 0;
			overflow: visible;

			.demo-block {
				// margin-top: 0px;
				margin: 0;
			}
		}
	}
</style>