<template>
	<div class="nuic background-pink">
		<img class="logo" src="@/assets/images/logo-2.png" />
		<div class="header" v-show="!loading">
			<div class="close" @click="onClose">
				<svg-icon name="close-border" size="33" />
			</div>

			<div
				class="item"
				v-for="(v, i) in list"
				:key="i"
				:state="active === i ? 1 : active > i ? 0 : 2"
			>
				<img
					v-show="i === active"
					src="@/assets/images/nuic/nav-active.png"
					draggable="false"
				/>
			</div>
		</div>
		<component v-show="!loading" class="view" :is="list[active]" @next="onNext" />
		<div class="loading" v-show="loading">
			<img src="@/assets/images/nuic/loading.png" />
			<p class="tip">{{ $t('Nuic.loadingTip') }}</p>
		</div>
	</div>
</template>

<script setup lang="ts">
	import { computed, ref, markRaw } from 'vue'
	import nuic1 from './nuic-1.vue'
	import nuic2 from './nuic-2.vue'
	import nuic3 from './nuic-3.vue'
	import { useRouter, useRoute } from 'vue-router'
	const router = useRouter()
	const route = useRoute()
	const active = computed(() => Number(route.query.index || 0))
	const list = markRaw([nuic1, nuic2, nuic3])
	const loading = ref(false)
	const onClose = () => {
		router.push({ name: 'mainInput' })
	}
	const onNext = () => {
		const index = active.value + 1
		if (index < list.length) {
			router.push({ query: { index } })
		} else {
			loading.value = true
			setTimeout(() => {
				router.push({ name: 'mainInput' })
			}, 1000)
		}
	}
</script>

<style lang="less" scoped>
	.nuic {
		width: 100%;
		height: 100%;
		overflow: hidden;
		position: relative;
		display: flex;
		flex-direction: column;
		// align-items: center;
		// justify-content: center;
		> .logo {
			position: absolute;
			top: 2.7rem;
			left: 3.6rem;
			width: auto;
			height: 2.4rem;
		}
		> .header {
			margin-top: 5rem;
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: flex-end;
			height: 11.2rem;
			> * {
				margin-right: 3rem;
				&:last-child {
					margin-right: 0;
				}
			}
			> .close {
				margin-bottom: -0.65rem;
				cursor: pointer;
			}
			> .item {
				width: 30.2rem;
				&[state='1'] {
					height: 100%;
				}
				&[state='2'],
				&[state='0'] {
					height: 2rem;
					border-radius: 2rem;
				}
				&[state='0'] {
					background: linear-gradient(90deg, #ff8ca2 0%, #ffa497 49.04%, #ff8d55 100%);
				}
				&[state='2'] {
					background-color: #dfdfdf;
				}
				> img {
					width: 100%;
					height: auto;
				}
			}
		}
		&:deep(.view) {
			margin-top: 5rem;
			display: flex;
			flex-direction: column;
			align-items: center;
			color: #252727;
			text-align: center;
			> .btns {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				> button {
					width: 29.6rem;
					height: 6rem;
					border-radius: 6rem;
					border: none;
					outline: none;
					font-size: 2.4rem;
					font-weight: 600;
					color: #252727;
					cursor: pointer;
					margin-right: 3.4rem;
					background-color: #fff;
					font-family: SemiBold;
					&:last-child {
						margin-right: 0;
					}
					&.skip {
						color: #8d8d8d;
					}
					&:active {
						opacity: 0.8;
					}
				}
			}
		}
		> .loading {
			width: 100%;
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			background-color: #f8f7f5;
			> .tip {
				font-family: Regular;
				font-size: 3rem;
				color: #585858;
			}
		}
	}
</style>
