<template>
	<view class="s-header">
		<view class="header-search">
			<zzx-icon name="search" size="16"></zzx-icon>
			<input type="text" v-model="searchText" placeholder="搜索俱乐部名称" />
			<view class="search-btn" @click="to_search">
				搜索
			</view>
		</view>
		<view class="venue-navbar">
			<view class="navbar-list" v-for="(item,index) in navbarList" :key="index" @click="select_nav(index)">
				<view class="list-text">{{item.text}}</view>
				<image :src="sel_index==index?'/static/notsel-icon.png':'/static/select-icon.png'" mode=""></image>
			</view>
		</view>
	</view>
	<view class="content">
		<view class="select-btn">
			<view :class="sel_btn===index?'distance':'score'" v-for="(item,index) in selectList" :key="index"
				@click="select_btn(index)">{{item}}</view>
		</view>
		<view class="s-search-list">
			<!-- 场地 -->
			<view class="s-venue-card">
				<view class="s-venue-info">
					<view class="venue-img">
						<image src="https://img.keaitupian.cn/newupload/08/1629449018344288.jpg" mode=""></image>
					</view>
					<view class="venue-info">
						<view class="name">体育综合训练馆(观山湖店)</view>
						<view class="appraise">
							<zzx-icon name="star" size="12"></zzx-icon>
							<view class="app-text"><text style="color: #FDD143	;">4.8</text> | 37条评论</view>
						</view>
						<view class="address">观山湖区万达广场 | 2.2km</view>
						<view class="tags-box">
							<view class="tags" v-for="item in 4">羽毛球</view>
						</view>
					</view>
				</view>
				<view class="s-course-list" v-for="item in 2">
					<view class="course-name">
						<view class="price">￥25.6</view>
						<view class="name">室内小班篮球培训课时</view>
					</view>
					<view class="sales">年售1万+</view>
				</view>
			</view>
			<!-- 培训 -->
			<view class="s-training-card">
				<view class="training-box">
					<view class="training-img">
						<image class="t-img" src="https://img.keaitupian.cn/newupload/08/1629449018344288.jpg" mode="">
						</image>
						<image class="img-tags" src="@/static/search-icon2.png" mode="widthFix"></image>
						<view class="tags-text">限时特惠</view>
						<view class="s-downtime">
							<view class="hours">{{hours}}</view>
							<view class="unit">:</view>
							<view class="hours">{{minutes}}</view>
							<view class="unit">:</view>
							<view class="hours">{{seconds}}</view>
						</view>
					</view>
					<view class="training-info">
						<view class="training-name">
							<view class="t-tags">公益课</view>
							<view class="t-name textHidden">1对1篮球30分钟室内30分钟室内</view>
						</view>
						<view class="tips">促进青少年长高</view>
						<view class="t-price">
							<view class="price"><text class="mini-text">￥</text>25.9</view>
							<view class="price-tips">不支持退款</view>
						</view>
						<view class="sales">已售37 98%好评</view>
						<view class="address">观山湖区万达广场 | 2.2km</view>
					</view>
				</view>
				<view class="tags-img">
					<image class="enroll-tags" src="@/static/search-icon1.png" mode="widthFix"></image>
				</view>
			</view>
			<!-- 赛事 -->
			<view class="">
				<events/>
			</view>
			<!-- 教练 -->
			<view class="">
				<instructor/>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref, onMounted } from 'vue';
	import events from './components/events.vue'
	import instructor from './components/instructor.vue'
	const selectList = ref(['距离', '好评'])
	const sel_index = ref(0);
	const sel_btn = ref(0);
	const hours = ref<string>('00');
	const minutes = ref<string>('00');
	const seconds = ref<string>('00');
	// 设置结束时间 (格式：YYYY-MM-DD HH:mm:ss)
	const endTime = ref<string>('2025-06-23 23:59:59');
	const navbarList = ref([{
		text: '场地'
	}, {
		text: '培训'
	}, {
		text: '赛事'
	}, {
		text: '教练'
	}]);
	onMounted(() => {
		updateCountdown();
		timer = setInterval(updateCountdown, 1000) as unknown as number;// 设置每秒更新
	})
	const select_btn = (i) => {
		sel_btn.value = i
	}
	const select_nav = (i) => {
		sel_index.value = i
	}
	// 倒计时
	let timer : number | null = null;
	const updateCountdown = () => {
		const now = new Date().getTime();
		const endDate = new Date(endTime.value).getTime();
		const timeLeft = endDate - now;
		if (timeLeft <= 0) {
			hours.value = '00';
			minutes.value = '00';
			seconds.value = '00';
			if (timer) {
				clearInterval(timer);
				timer = null;
			}
			return;
		}
		// 计算剩余时间
		const d = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
		const h = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
		const m = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
		const s = Math.floor((timeLeft % (1000 * 60)) / 1000);
		// 格式化为两位数
		hours.value = h.toString().padStart(2, '0');
		minutes.value = m.toString().padStart(2, '0');
		seconds.value = s.toString().padStart(2, '0');
	};
</script>

<style lang="less" scoped>
	.s-header {
		background: #fff;
		padding: 20rpx;

		.header-search {
			display: flex;
			align-items: center;
			gap: 10rpx;
			background: #F6F6F6;
			width: 700rpx;
			height: 60rpx;
			border-radius: 40rpx;

			&>input {
				width: 670rpx;
				font-weight: bold;
				font-size: 24rpx;
			}

			.search-btn {
				width: 144rpx;
				height: 52rpx;
				background: #222222;
				border-radius: 28rpx;
				font-weight: bold;
				font-size: 28rpx;
				color: #C8FF0C;
				line-height: 52rpx;
				text-align: center;
			}
		}

		.venue-navbar {
			margin-top: 32rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.navbar-list {
				display: flex;
				align-items: center;
				gap: 10rpx;

				.list-text {
					font-weight: bold;
					font-size: 28rpx;
					color: #222222;
				}

				&>image {
					width: 30rpx;
					height: 30rpx;
				}
			}
		}
	}

	.content {
		.select-btn {
			display: flex;
			align-items: center;
			gap: 20rpx;
			margin-top: 20rpx;

			.distance {
				width: 92rpx;
				height: 48rpx;
				background: #222222;
				border-radius: 8rpx;
				font-size: 28rpx;
				color: #C8FF0C;
				line-height: 48rpx;
				text-align: center;
			}

			.score {
				width: 92rpx;
				height: 48rpx;
				background: #FFFFFF;
				border-radius: 8rpx;
				font-size: 28rpx;
				color: #AAAAAA;
				height: 48rpx;
				line-height: 48rpx;
				text-align: center;
			}
		}

		.s-search-list {
			.s-venue-card {
				margin-top: 20rpx;
				background: #FFFFFF;
				border-radius: 32rpx;
				padding: 20rpx;

				.s-venue-info {
					display: flex;
					align-items: center;
					gap: 20rpx;

					.venue-img {
						&>image {
							width: 200rpx;
							height: 200rpx;
							border-radius: 32rpx;
						}
					}

					.venue-info {
						.name {
							font-weight: 800;
							font-size: 32rpx;
							color: #222222;
						}

						.appraise {
							display: flex;
							align-items: center;
							margin-top: 16rpx;

							.app-text {
								font-size: 24rpx;
								color: #AAAAAA;
							}
						}

						.address {
							margin-top: 12rpx;
							font-size: 24rpx;
							color: #222222;
						}

						.tags-box {
							margin-top: 16rpx;
							display: flex;
							align-items: center;
							gap: 12rpx;

							.tags {
								width: 92rpx;
								height: 36rpx;
								background: #F5F5F5;
								border-radius: 8rpx;
								font-size: 22rpx;
								color: #AAAAAA;
								line-height: 36rpx;
								text-align: center;
							}
						}
					}
				}

				.s-course-list {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 20rpx;

					.course-name {
						display: flex;
						align-items: center;
						gap: 20rpx;
						font-weight: bold;
						font-size: 28rpx;

						.price {
							color: #FB5B5B;
						}

						.name {
							color: #222222;
						}
					}

					.sales {
						font-size: 24rpx;
						color: #AAAAAA;
					}
				}
			}

			.s-training-card {
				margin-top: 20rpx;
				background: #FFFFFF;
				border-radius: 32rpx;
				padding: 20rpx;
				position: relative;

				.training-box {
					display: flex;
					align-items: center;
					gap: 20rpx;

					.training-img {
						position: relative;

						.t-img {
							width: 200rpx;
							height: 200rpx;
							border-radius: 32rpx;
						}

						.img-tags {
							position: absolute;
							left: -20rpx;
							top: 0;
							width: 113rpx;
						}

						.tags-text {
							position: absolute;
							font-size: 18rpx;
							color: #FFFFFF;
							top: 14rpx;
							left: 0;
						}

						.s-downtime {
							position: absolute;
							display: flex;
							bottom: 20rpx;
							left: 18rpx;

							.hours {
								width: 40rpx;
								height: 40rpx;
								background: rgba(200, 255, 12, 0.5);
								border-radius: 8rpx;
								font-weight: 800;
								font-size: 22rpx;
								color: #222222;
								line-height: 40rpx;
								text-align: center;
							}

							.unit {
								width: 20rpx;
								font-weight: 800;
								font-size: 22rpx;
								color: #222222;
								line-height: 40rpx;
								text-align: center;
							}
						}
					}

					.training-info {
						.training-name {
							display: flex;
							align-items: center;
							gap: 8rpx;

							.t-tags {
								width: 92rpx;
								height: 36rpx;
								background: #4DD951;
								border-radius: 8rpx;
								font-size: 22rpx;
								color: #FFFFFF;
								text-align: center;
								line-height: 36rpx;
							}

							.t-name {
								width: 360rpx;
								font-weight: 800;
								font-size: 32rpx;
								color: #222222;
							}
						}

						.tips {
							font-size: 22rpx;
							color: #AAAAAA;
						}

						.t-price {
							display: flex;
							align-items: center;
							gap: 12rpx;

							.price {
								font-weight: 800;
								font-size: 32rpx;
								color: #FB5B5B;
							}

							.price-tips {
								margin-top: 8rpx;
								width: 176rpx;
								height: 42rpx;
								background: linear-gradient(90deg, #C8FF0C 0%, #F2FFC7 79%, rgba(255, 255, 255, 0) 100%);
								border-radius: 28rpx;
								font-size: 22rpx;
								color: #222222;
								line-height: 42rpx;
								text-align: center;
							}
						}

						.sales {
							margin-top: 8rpx;
							font-size: 22rpx;
							color: #222222;
						}

						.address {
							margin-top: 8rpx;
							font-size: 22rpx;
							color: #222222;
						}
					}
				}

				.tags-img {
					position: absolute;
					right: 0;
					bottom: 0;

					.enroll-tags {
						width: 161rpx;
					}
				}

			}
		}
	}
</style>