<template>
	<view class="preference-setting">
		<!-- 自定义导航栏 -->
		<view class="custom-navbar">
			<view class="navbar-content">
				<view class="nav-left" @click="goBack">
					<u-icon name="close" color="#333" size="32"></u-icon>
				</view>
				<view class="nav-title">从事偏好设置</view>
				<view class="nav-right"></view>
			</view>
		</view>
		
		<!-- 主要内容 -->
		<view class="main-content">
			<view class="job-title">{{ jobTitle }}-职位偏好</view>
			<view class="description">根据你的偏好设置,为你推荐更匹配的职位</view>
			
			<view class="preference-section">
				<view class="section-title">请选择你的从事偏好</view>
				
				<!-- 偏好标签网格 -->
				<view class="preference-grid">
					<view 
						v-for="(item, index) in preferenceOptions" 
						:key="index"
						class="preference-tag"
						:class="{ active: selectedPreferences.includes(item) }"
						@click="togglePreference(item)"
					>
						<text>{{ item }}</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 底部确定按钮 -->
		<view class="bottom-btn-container">
			<view class="confirm-btn" @click="confirmSelection">
				<text>确定</text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			jobTitle: '亚马逊运营总监',
			selectedPreferences: ['独立站'],
			preferenceOptions: [
				'精品铺货', '独立站', '3C数码', '美妆日用', '服装配饰', '家居用品',
				'户外运动', '母婴用品', '食品饮料', '宠物用品', '汽车用品', '图书文具',
				'数码配件', '办公用品', '礼品玩具', '健康保健', '珠宝首饰', '箱包皮具',
				'手表眼镜', '乐器音响', '摄影摄像', '运动健身', '旅游出行', '教育培训',
				'金融服务', '生活服务', '其他'
			]
		}
	},
	onLoad(options) {
		if (options.jobTitle) {
			this.jobTitle = decodeURIComponent(options.jobTitle)
		}
		if (options.selectedPreferences) {
			this.selectedPreferences = JSON.parse(decodeURIComponent(options.selectedPreferences))
		}
	},
	methods: {
		goBack() {
			uni.navigateBack()
		},
		togglePreference(item) {
			const index = this.selectedPreferences.indexOf(item)
			if (index > -1) {
				// 如果已选中，则取消选中
				this.selectedPreferences.splice(index, 1)
			} else {
				// 如果未选中，则添加到选中列表
				this.selectedPreferences.push(item)
			}
		},
		confirmSelection() {
			// 返回选中的偏好设置
			uni.navigateBack({
				delta: 1
			})
			
			// 通知父页面更新偏好设置
			uni.$emit('preferenceUpdated', {
				jobTitle: this.jobTitle,
				preferences: this.selectedPreferences
			})
			
			uni.showToast({
				title: '偏好设置已保存',
				icon: 'success'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.preference-setting {
	min-height: 100vh;
	background: #fff;
	display: flex;
	flex-direction: column;
    padding: 88rpx 40rpx 40rpx 40rpx;
}

.navbar-content {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 88rpx;
}

.nav-left, .nav-right {
	width: 60rpx;
	height: 60rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.nav-title {
    color: rgba(51, 51, 51, 1);
    font-family: DM Sans;
    font-size: 36rpx;
    font-weight: 700;
    line-height: 26px;
    letter-spacing: 0px;
    text-align: center;
}

.main-content {
    margin-top:20rpx;
}

.job-title {
    color: rgba(51, 51, 51, 1);
    font-family: DM Sans;
    font-size: 52rpx;
    font-weight: 700;
    line-height: 30px;
    letter-spacing: 0px;
    text-align: left;
}

.description {
    margin:20rpx 0;
    color: rgba(102, 102, 102, 1);
    font-family: DM Sans;
    font-size: 28rpx;
    font-weight: 400;
    letter-spacing: 0px;
    text-align: left;
}

.preference-section {
	margin-bottom: 40rpx;
}

.section-title {
    color: rgba(34, 37, 42, 1);
    font-family: DM Sans;
    font-size: 36rpx;
    font-weight: 400;
    line-height: 24px;
    letter-spacing: 0px;
    text-align: left;
    margin-bottom: 20rpx;
}

.preference-grid {
	display: flex;
	flex-wrap: wrap;
	gap: 12rpx;
}

.preference-tag {
	width: calc((100% - 72rpx) / 7);
	padding: 8rpx 6rpx;
	background: #F7F8FA;
	border: 1rpx solid #F7F8FA;
	border-radius: 12rpx;
	transition: all 0.3s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	
	text {
		font-size: 18rpx;
		color: rgba(102, 102, 102, 1);
		font-weight: 400;
		text-align: center;
		line-height: 1.2;
	}
	
	&.active {
		background: rgba(153, 196, 250, 0.4);
		border: 0.5px solid  rgba(1, 107, 246, 1);
		
		text {
			color: rgba(1, 107, 246, 1);
			font-weight: 400;
		}
	}
	
	&:active {
		transform: scale(0.95);
	}
}

.bottom-btn-container {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	padding: 32rpx;
	background: #fff;
	border-top: 1px solid #f0f0f0;
}

.confirm-btn {
	width: 100%;
	height: 88rpx;
	background: #007AFF;
	border-radius: 44rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	
	text {
		font-size: 32rpx;
		font-weight: 600;
		color: #fff;
	}
	
	&:active {
		background: #0056CC;
	}
}
</style>
