<template>
	<view class="customize-page">
		<!-- 顶部导航栏 -->
		<view class="header">
			<view class="back-btn" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<text class="header-title">私人定制</text>
			<view class="placeholder"></view>
		</view>

		<scroll-view scroll-y class="content">

			<!-- 年龄范围 -->
			<view class="card-section">
				<view class="card-title">年龄范围</view>
				<view class="age-range">
					<slider 
						class="age-slider"
						:value="ageRange" 
						:min="18" 
						:max="60" 
						:step="1"
						activeColor="#3B9FF3"
						backgroundColor="#E0E0E0"
						block-size="24"
						@change="onAgeChange"
					/>
					<view class="range-values">
						<text class="range-value">{{ minAge }}</text>
						<text class="range-value">{{ maxAge }}</text>
					</view>
				</view>
			</view>

			<!-- 兴趣标签 -->
			<view class="card-section">
				<view class="card-title">兴趣标签</view>
				<view class="tags-container">
					<view 
						class="tag-item" 
						v-for="(tag, index) in interestTags" 
						:key="index"
						:class="{ 'tag-selected': tag.selected }"
						@click="toggleTag(index)"
					>
						<text class="tag-text">{{ tag.name }}</text>
					</view>
					<view class="tag-item tag-more">
						<text class="tag-text">····</text>
					</view>
				</view>
			</view>

			<!-- 择偶优先级 -->
			<view class="card-section">
				<view class="card-title">择偶优先级</view>
				<view class="priority-list">
					<view class="priority-item" v-for="(item, index) in priorities" :key="index">
						<view class="priority-left">
							<text class="priority-icon">{{ item.icon }}</text>
							<text class="priority-text">{{ item.name }}</text>
						</view>
						<switch 
							:checked="item.enabled" 
							@change="onPriorityChange($event, index)"
							color="#3B9FF3"
						/>
					</view>
				</view>
			</view>

			<!-- 底部按钮 -->
			<view class="bottom-button">
				<button class="generate-btn" @click="generatePlan">立即生成方案</button>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ageRange: 30,
				minAge: 20,
				maxAge: 45,
				interestTags: [
					{ name: '阅读', selected: false },
					{ name: '音乐', selected: false },
					{ name: '健身', selected: false },
					{ name: '宠物', selected: false }
				],
				priorities: [
					{ icon: '🏠', name: '家庭', enabled: false },
					{ icon: '📋', name: '三观', enabled: false },
					{ icon: '💰', name: '收入', enabled: false },
					{ icon: '📏', name: '身高', enabled: false }
				]
			}
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			
			onAgeChange(e) {
				this.ageRange = e.detail.value
				// 假设范围是基于中间值的±范围
				this.minAge = Math.max(18, this.ageRange - 10)
				this.maxAge = Math.min(60, this.ageRange + 15)
			},
			
			toggleTag(index) {
				this.interestTags[index].selected = !this.interestTags[index].selected
			},
			
			onPriorityChange(e, index) {
				this.priorities[index].enabled = e.detail.value
			},
			
			generatePlan() {
				// 收集数据
				const selectedTags = this.interestTags.filter(t => t.selected).map(t => t.name)
				const selectedPriorities = this.priorities.filter(p => p.enabled).map(p => p.name)
				
				if (selectedTags.length === 0) {
					uni.showToast({
						title: '请至少选择一个兴趣标签',
						icon: 'none'
					})
					return
				}
				
				uni.showLoading({
					title: '生成方案中...'
				})
				
				// TODO: 调用后端接口生成定制方案
				setTimeout(() => {
					uni.hideLoading()
					uni.showModal({
						title: '方案生成成功',
						content: '您的专属脱单方案已生成，我们会为您推荐最合适的对象！',
						showCancel: false,
						success: () => {
							uni.navigateBack()
						}
					})
				}, 1500)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.customize-page {
		min-height: 100vh;
		background: #F5F5F5;
		display: flex;
		flex-direction: column;
	}

	/* 顶部导航栏 */
	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 25rpx 30rpx;
		padding-top: calc(25rpx + env(safe-area-inset-top));
		background: #FFFFFF;
		border-bottom: 1rpx solid #F0F0F0;
		
		.back-btn {
			width: 60rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.back-icon {
				font-size: 40rpx;
				color: #333333;
				font-weight: bold;
			}
		}
		
		.header-title {
			font-size: 36rpx;
			font-weight: bold;
			color: #333333;
		}
		
		.placeholder {
			width: 60rpx;
		}
	}

	.content {
		flex: 1;
	}


	/* 卡片区域 */
	.card-section {
		background: #FFFFFF;
		margin: 30rpx;
		padding: 35rpx 30rpx;
		border-radius: 20rpx;
		box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.05);
		
		.card-title {
			font-size: 32rpx;
			font-weight: bold;
			color: #333333;
			margin-bottom: 30rpx;
		}
	}

	/* 年龄范围 */
	.age-range {
		.age-slider {
			width: 100%;
		}
		
		.range-values {
			display: flex;
			justify-content: space-between;
			margin-top: 15rpx;
			
			.range-value {
				font-size: 28rpx;
				color: #666666;
			}
		}
	}

	/* 兴趣标签 */
	.tags-container {
		display: flex;
		flex-wrap: wrap;
		gap: 20rpx;
		
		.tag-item {
			padding: 15rpx 35rpx;
			background: #F5F5F5;
			border: 2rpx solid #E0E0E0;
			border-radius: 40rpx;
			transition: all 0.3s;
			
			.tag-text {
				font-size: 28rpx;
				color: #666666;
			}
			
			&.tag-selected {
				background: #E3F2FD;
				border-color: #3B9FF3;
				
				.tag-text {
					color: #3B9FF3;
					font-weight: 500;
				}
			}
			
			&.tag-more {
				background: transparent;
				border-style: dashed;
				
				.tag-text {
					color: #999999;
				}
			}
		}
	}

	/* 择偶优先级 */
	.priority-list {
		.priority-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 25rpx 0;
			border-bottom: 1rpx solid #F5F5F5;
			
			&:last-child {
				border-bottom: none;
			}
			
			.priority-left {
				display: flex;
				align-items: center;
				
				.priority-icon {
					font-size: 36rpx;
					margin-right: 20rpx;
				}
				
				.priority-text {
					font-size: 30rpx;
					color: #333333;
				}
			}
			
			switch {
				transform: scale(0.85);
			}
		}
	}

	/* 底部按钮 */
	.bottom-button {
		padding: 40rpx 60rpx;
		padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
		
		.generate-btn {
			width: 100%;
			height: 90rpx;
			background: linear-gradient(135deg, #FF8EC0 0%, #FFB3D5 100%);
			color: #FFFFFF;
			font-size: 34rpx;
			font-weight: bold;
			border: none;
			border-radius: 45rpx;
			box-shadow: 0 8rpx 30rpx rgba(255, 142, 192, 0.4);
		}
	}
</style>
