<template>
	<div class="top-nav" :style_="topNavStyle">
		<span class="icon" v-show="topNavStyle === '2'" @click="onBack">
			<svg-icon name="back" size="18" />
		</span>
		<p class="division"></p>
		<div class="credits-box">
			<span class="credits">Credits: 6000</span>
			<span class="icon" @click="onRefresh" :class="{ loading }">
				<svg-icon name="refresh" size="21" />
			</span>
			<span class="link"></span>
			<span class="icon" @click="onShop"><svg-icon name="shop" size="21" /></span>
		</div>
		<img class="pic" src="@/assets/images/pic.jpg" />
	</div>
</template>

<script setup lang="ts">
	import { computed, ref } from 'vue'
	import { useRoute, useRouter } from 'vue-router'
	const route = useRoute()
	const topNavStyle = computed(() => route.meta.topNavStyle)
	const router = useRouter()
	const loading = ref(false)
	const onBack = () => {
		router.back()
	}
	const onShop = () => {
		console.log('onShop')
		// router.push({ name: 'shop' })
	}
	const onRefresh = () => {
		console.log('onRefresh')
		loading.value = true
		setTimeout(() => {
			loading.value = false
		}, 1500)
	}
</script>

<style lang="less" scoped>
	.top-nav {
		height: 8rem;
		display: flex;
		align-items: center;
		padding: 0 2rem 0 3rem;
		&[style_='1'] {
			border-bottom: 1px solid rgba(201, 201, 201, 1);
		}
		&[style_='2'] {
			border-bottom: 1px solid rgba(201, 201, 201, 1);
			background-color: #fff;
		}
		> .division {
			margin: auto;
		}
		> .icon {
			cursor: pointer;
			width: 2.4rem;
			height: 2.4rem;
		}
		> .credits-box {
			display: flex;
			align-items: center;
			justify-content: center;
			min-width: 18rem;
			height: 4.3rem;
			margin-right: 1rem;
			background-color: rgba(255, 252, 244, 1);
			border: 1px solid rgba(233, 121, 60, 1);
			border-radius: 0.8rem;
			> .credits {
				flex: 1;
				font-size: 1.3rem;
				margin-left: 1rem;
			}
			> .link {
				height: 100%;
				width: 0;
				border-right: 1px solid rgba(233, 121, 60, 1);
			}
			> .icon {
				cursor: pointer;
				margin: 0 1rem;
			}
			> .loading {
				animation: loading 0.6s linear infinite;
			}
		}
		> .pic {
			width: 4.65rem;
			height: 4.65rem;
			border-radius: 50%;
		}
	}
</style>
