<template>
	<view class="astrology-page">
		<!-- 自定义顶部导航栏 -->
		<view class="custom-nav">
			<view class="nav-left" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<view class="nav-title">星命运算</view>
			<view class="nav-right">
				<text class="menu-icon">⋯</text>
			</view>
		</view>

		<!-- 测算卡片区域 -->
		<view class="cards-section">
			<view class="card-item" v-for="(card, index) in cardList" :key="index" @click="handleCardClick(card)">
				<view class="card-icon">{{ card.icon }}</view>
				<view class="card-name">{{ card.name }}</view>
				<view class="card-desc">{{ card.desc }}</view>
			</view>
		</view>

		<!-- 星座配对测试 -->
		<view class="match-test-banner" @click="handleConstellationMatch">
			<view class="match-banner-content">
				<view class="match-icon-group">
					<text class="match-icon">💫</text>
				</view>
				<view class="match-text-group">
					<view class="match-title">星座配对测试</view>
					<view class="match-subtitle">测测你们的星座匹配度有多高</view>
				</view>
				<view class="match-arrow">→</view>
			</view>
			<view class="match-stats">
				<text class="match-stats-text">💕 今日已有 {{ matchTestCount }} 对情侣测试</text>
			</view>
		</view>

		<!-- 我的爱情运势 -->
		<view class="love-fortune">
			<view class="section-title">
				<text class="title-text">❤️ 我的爱情运势</text>
				<text class="title-date">{{ todayDate }}</text>
			</view>
			<view class="fortune-cards">
				<view class="fortune-card" v-for="(item, index) in loveFortune" :key="index">
					<view class="fortune-icon" :style="{background: item.color}">
						<text class="fortune-emoji">{{ item.icon }}</text>
					</view>
					<view class="fortune-info">
						<text class="fortune-label">{{ item.label }}</text>
						<view class="fortune-score">
							<view class="score-bar">
								<view class="score-fill" :style="{width: item.score + '%', background: item.color}"></view>
							</view>
							<text class="score-text">{{ item.score }}%</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 本周脱单指数 -->
		<view class="single-index">
			<view class="section-title">
				<text class="title-text">📊 本周脱单指数</text>
			</view>
			<view class="index-card">
				<view class="index-header">
					<view class="index-score-wrapper">
						<text class="index-score">{{ singleIndex.score }}</text>
						<text class="index-unit">分</text>
					</view>
					<view class="index-level" :style="{background: singleIndex.levelColor}">
						{{ singleIndex.level }}
					</view>
				</view>
				<view class="index-tips">
					<view class="tip-item" v-for="(tip, index) in singleIndex.tips" :key="index">
						<text class="tip-icon">{{ tip.icon }}</text>
						<text class="tip-text">{{ tip.text }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 每日幸运推荐 -->
		<view class="lucky-recommend">
			<view class="section-title">
				<text class="title-text">🎁 今日幸运推荐</text>
			</view>
			<view class="lucky-grid">
				<view class="lucky-item" v-for="(item, index) in luckyRecommend" :key="index">
					<view class="lucky-icon-wrapper" :style="{background: item.bgColor}">
						<text class="lucky-icon">{{ item.icon }}</text>
					</view>
					<text class="lucky-label">{{ item.label }}</text>
					<text class="lucky-value">{{ item.value }}</text>
				</view>
			</view>
		</view>

		<!-- 热门测试榜单 -->
		<view class="hot-tests">
			<view class="section-title">
				<text class="title-text">🔥 热门测试榜单</text>
				<text class="title-more">查看全部 ></text>
			</view>
			<view class="test-list">
				<view class="test-item" v-for="(item, index) in hotTests" :key="index" @click="handleTestClick(item)">
					<view class="test-rank" :class="{'top-rank': index < 3}">{{ index + 1 }}</view>
					<view class="test-info">
						<text class="test-name">{{ item.name }}</text>
						<text class="test-count">{{ item.count }} 人已测</text>
					</view>
					<view class="test-tag" v-if="item.isNew">NEW</view>
				</view>
			</view>
		</view>

		<!-- 底部占位 -->
		<view class="bottom-placeholder"></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 今日日期
			todayDate: '',
			
			// 测算卡片
			cardList: [
				{
					id: 1,
					name: '属相卡片',
					icon: '🐷',
					desc: '2.3万人测过',
					type: 'zodiac'
				},
				{
					id: 2,
					name: '星座卡片',
					icon: '♓',
					desc: '2.3万人测过',
					type: 'constellation'
				},
				{
					id: 3,
					name: '八字卡片',
					icon: '☯',
					desc: '2.3万人测过',
					type: 'bazi'
				},
				{
					id: 4,
					name: 'MBTI卡片',
					icon: '🧩',
					desc: '2.3万人测过',
					type: 'mbti'
				}
			],

			// 缘分配对测试统计
			matchTestCount: 1234,

			// 我的爱情运势
			loveFortune: [
				{
					label: '桃花运',
					icon: '🌸',
					score: 85,
					color: 'linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%)'
				},
				{
					label: '爱情指数',
					icon: '💕',
					score: 78,
					color: 'linear-gradient(135deg, #E91E63 0%, #FF6B9D 100%)'
				},
				{
					label: '魅力值',
					icon: '✨',
					score: 92,
					color: 'linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%)'
				}
			],

			// 本周脱单指数
			singleIndex: {
				score: 88,
				level: '极佳',
				levelColor: 'linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%)',
				tips: [
					{ icon: '📅', text: '最佳约会日：周六' },
					{ icon: '⏰', text: '最佳时间：下午2-5点' },
					{ icon: '📍', text: '推荐地点：咖啡厅、公园' }
				]
			},

			// 每日幸运推荐
			luckyRecommend: [
				{
					label: '幸运色',
					icon: '🎨',
					value: '粉红色',
					bgColor: 'linear-gradient(135deg, #FFB6C1 0%, #FFE4E1 100%)'
				},
				{
					label: '幸运数字',
					icon: '🔢',
					value: '7',
					bgColor: 'linear-gradient(135deg, #9C27B0 0%, #CE93D8 100%)'
				},
				{
					label: '约会建议',
					icon: '💡',
					value: '浪漫晚餐',
					bgColor: 'linear-gradient(135deg, #FF9800 0%, #FFB74D 100%)'
				},
				{
					label: '穿搭风格',
					icon: '👗',
					value: '清新甜美',
					bgColor: 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)'
				}
			],

			// 热门测试榜单
			hotTests: [
				{
					id: 1,
					name: '恋爱性格测试',
					count: '12.8万',
					isNew: false
				},
				{
					id: 2,
					name: '理想型匹配度',
					count: '10.5万',
					isNew: true
				},
				{
					id: 3,
					name: '爱情观测试',
					count: '9.2万',
					isNew: false
				},
				{
					id: 4,
					name: '婚姻契合度',
					count: '8.6万',
					isNew: false
				},
				{
					id: 5,
					name: '恋爱EQ测试',
					count: '7.3万',
					isNew: true
				}
			]
		}
	},

	onLoad() {
		this.initData()
	},

	methods: {
		// 初始化数据
		initData() {
			// 设置今日日期
			const date = new Date()
			const month = date.getMonth() + 1
			const day = date.getDate()
			const weekDays = ['日', '一', '二', '三', '四', '五', '六']
			const weekDay = weekDays[date.getDay()]
			this.todayDate = `${month}月${day}日 周${weekDay}`
		},

		// 返回上一页
		goBack() {
			// 检查页面栈
			const pages = getCurrentPages()
			if (pages.length > 1) {
				// 有上一页，正常返回
				uni.navigateBack({
					delta: 1
				})
			} else {
				// 没有上一页，跳转到首页
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		},

		// 卡片点击
		handleCardClick(card) {
			// 根据不同类型跳转到不同页面
			const pageMap = {
				'zodiac': '/pages/astrology/zodiac',
				'constellation': '/pages/astrology/constellation',
				'bazi': '/pages/astrology/bazi',
				'mbti': '/pages/astrology/mbti'
			}

			const page = pageMap[card.type]
			if (page) {
				uni.navigateTo({
					url: page
				})
			} else {
				uni.showToast({
					title: `${card.name}功能开发中`,
					icon: 'none'
				})
			}
		},

		// 星座配对测试
		handleConstellationMatch() {
			uni.navigateTo({
				url: '/pages/astrology/constellation-match'
			})
		},

		// 测试项点击
		handleTestClick(test) {
			uni.showToast({
				title: `${test.name}功能开发中`,
				icon: 'none'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.astrology-page {
	min-height: 100vh;
	background: linear-gradient(180deg, #FFF9F9 0%, #FFFFFF 50%);
	padding-bottom: 40rpx;
}

/* 自定义导航栏 */
.custom-nav {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 88rpx;
	padding: 0 30rpx;
	background-color: #FFFFFF;
	border-bottom: 1rpx solid #F0F0F0;

	.nav-left {
		width: 80rpx;

		.back-icon {
			font-size: 40rpx;
			color: #333333;
		}
	}

	.nav-title {
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		font-size: 34rpx;
		font-weight: 600;
		color: #333333;
	}

	.nav-right {
		width: 80rpx;
		text-align: right;

		.menu-icon {
			font-size: 40rpx;
			color: #333333;
		}
	}
}

/* 测算卡片区域 */
.cards-section {
	display: flex;
	justify-content: space-around;
	padding: 40rpx 30rpx 30rpx;
	background-color: #FFFFFF;

	.card-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 160rpx;
		transition: transform 0.2s;

		&:active {
			transform: scale(0.95);
		}

		.card-icon {
			width: 120rpx;
			height: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: linear-gradient(135deg, #F3E5F5 0%, #E1BEE7 100%);
			border-radius: 20rpx;
			font-size: 60rpx;
			margin-bottom: 15rpx;
			box-shadow: 0 4rpx 12rpx rgba(156, 39, 176, 0.15);
		}

		.card-name {
			font-size: 28rpx;
			color: #333333;
			font-weight: 500;
			margin-bottom: 8rpx;
		}

		.card-desc {
			font-size: 22rpx;
			color: #999999;
		}
	}
}

/* 通用标题样式 */
.section-title {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 20rpx;

	.title-text {
		font-size: 32rpx;
		font-weight: 600;
		color: #333333;
	}

	.title-date {
		font-size: 24rpx;
		color: #999999;
	}

	.title-more {
		font-size: 24rpx;
		color: #E91E63;
	}
}

/* 缘分配对测试 */
.match-test-banner {
	margin: 30rpx;
	background: linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%);
	border-radius: 20rpx;
	padding: 30rpx;
	box-shadow: 0 8rpx 20rpx rgba(233, 30, 99, 0.25);
	transition: transform 0.2s;

	&:active {
		transform: scale(0.98);
	}

	.match-banner-content {
		display: flex;
		align-items: center;
		margin-bottom: 15rpx;

		.match-icon-group {
			width: 80rpx;
			height: 80rpx;
			background-color: rgba(255, 255, 255, 0.3);
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 20rpx;

			.match-icon {
				font-size: 48rpx;
			}
		}

		.match-text-group {
			flex: 1;

			.match-title {
				font-size: 32rpx;
				font-weight: 600;
				color: #FFFFFF;
				margin-bottom: 8rpx;
			}

			.match-subtitle {
				font-size: 24rpx;
				color: rgba(255, 255, 255, 0.9);
			}
		}

		.match-arrow {
			font-size: 40rpx;
			color: #FFFFFF;
			font-weight: bold;
		}
	}

	.match-stats {
		.match-stats-text {
			font-size: 22rpx;
			color: rgba(255, 255, 255, 0.85);
		}
	}
}

/* 我的爱情运势 */
.love-fortune {
	margin: 30rpx;

	.fortune-cards {
		display: flex;
		flex-direction: column;
		gap: 15rpx;

		.fortune-card {
			display: flex;
			align-items: center;
			background-color: #FFFFFF;
			border-radius: 15rpx;
			padding: 25rpx;
			box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);

			.fortune-icon {
				width: 70rpx;
				height: 70rpx;
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 20rpx;

				.fortune-emoji {
					font-size: 36rpx;
				}
			}

			.fortune-info {
				flex: 1;

				.fortune-label {
					font-size: 28rpx;
					color: #333333;
					font-weight: 500;
					margin-bottom: 12rpx;
					display: block;
				}

				.fortune-score {
					display: flex;
					align-items: center;

					.score-bar {
						flex: 1;
						height: 12rpx;
						background-color: #F0F0F0;
						border-radius: 6rpx;
						overflow: hidden;
						margin-right: 15rpx;

						.score-fill {
							height: 100%;
							border-radius: 6rpx;
							transition: width 0.6s ease;
						}
					}

					.score-text {
						font-size: 26rpx;
						color: #E91E63;
						font-weight: 600;
						min-width: 60rpx;
						text-align: right;
					}
				}
			}
		}
	}
}

/* 本周脱单指数 */
.single-index {
	margin: 30rpx;

	.index-card {
		background: linear-gradient(135deg, #FFF3E0 0%, #FFE0B2 100%);
		border-radius: 20rpx;
		padding: 30rpx;
		box-shadow: 0 4rpx 12rpx rgba(255, 152, 0, 0.15);

		.index-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 25rpx;

			.index-score-wrapper {
				display: flex;
				align-items: baseline;

				.index-score {
					font-size: 72rpx;
					font-weight: bold;
					color: #FF6B6B;
					line-height: 1;
				}

				.index-unit {
					font-size: 28rpx;
					color: #666666;
					margin-left: 8rpx;
				}
			}

			.index-level {
				padding: 10rpx 25rpx;
				border-radius: 30rpx;
				font-size: 28rpx;
				color: #FFFFFF;
				font-weight: 600;
			}
		}

		.index-tips {
			display: flex;
			flex-direction: column;
			gap: 12rpx;

			.tip-item {
				display: flex;
				align-items: center;
				background-color: rgba(255, 255, 255, 0.7);
				border-radius: 10rpx;
				padding: 15rpx 20rpx;

				.tip-icon {
					font-size: 28rpx;
					margin-right: 12rpx;
				}

				.tip-text {
					font-size: 26rpx;
					color: #333333;
				}
			}
		}
	}
}

/* 每日幸运推荐 */
.lucky-recommend {
	margin: 30rpx;

	.lucky-grid {
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		gap: 20rpx;

		.lucky-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			background-color: #FFFFFF;
			border-radius: 15rpx;
			padding: 30rpx 20rpx;
			box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);

			.lucky-icon-wrapper {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-bottom: 15rpx;

				.lucky-icon {
					font-size: 40rpx;
				}
			}

			.lucky-label {
				font-size: 24rpx;
				color: #999999;
				margin-bottom: 8rpx;
			}

			.lucky-value {
				font-size: 28rpx;
				color: #333333;
				font-weight: 600;
			}
		}
	}
}

/* 热门测试榜单 */
.hot-tests {
	margin: 30rpx;

	.test-list {
		background-color: #FFFFFF;
		border-radius: 20rpx;
		overflow: hidden;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);

		.test-item {
			display: flex;
			align-items: center;
			padding: 25rpx 30rpx;
			border-bottom: 1rpx solid #F5F5F5;
			position: relative;
			transition: background-color 0.2s;

			&:last-child {
				border-bottom: none;
			}

			&:active {
				background-color: #F9F9F9;
			}

			.test-rank {
				width: 50rpx;
				height: 50rpx;
				background-color: #F0F0F0;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26rpx;
				font-weight: bold;
				color: #666666;
				margin-right: 20rpx;

				&.top-rank {
					background: linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%);
					color: #FFFFFF;
				}
			}

			.test-info {
				flex: 1;

				.test-name {
					font-size: 28rpx;
					color: #333333;
					font-weight: 500;
					display: block;
					margin-bottom: 8rpx;
				}

				.test-count {
					font-size: 22rpx;
					color: #999999;
				}
			}

			.test-tag {
				position: absolute;
				top: 15rpx;
				right: 30rpx;
				padding: 4rpx 12rpx;
				background: linear-gradient(135deg, #E91E63 0%, #FF6B9D 100%);
				color: #FFFFFF;
				font-size: 20rpx;
				border-radius: 6rpx;
				font-weight: bold;
			}
		}
	}
}

/* 底部占位 */
.bottom-placeholder {
	height: 40rpx;
}
</style>

