<template>
	<view class="page-wrap">
		<!-- ===== 顶部渐变导航栏 ===== -->
		<view class="header-gradient">
			<view class="nav-bar flex-between">
				<!-- 返回按钮 -->
				<view class="nav-btn" @click="goBack">
					<text class="wlIcon wlIcon-fanhui1"></text>
				</view>
				<!-- 页面标题 -->
				<text class="nav-title">酒店</text>
				<!-- 订单按钮 -->
				<view class="nav-btn" @click="toOrder">
					<text class="btn-text">订单</text>
				</view>
			</view>
		</view>
		<!-- Tab栏（国内/国际/钟点房/民宿/短租） -->
		<view class="tab-wrap">
			<view v-for="(item, index) in tabList" :key="index" class="tab-item" :class="{ active: currentTab === index }"
				@click="switchTab(index)">
				{{ item.label }}
			</view>
		</view>
		<!-- ===== 筛选白色卡片区域 ===== -->
		<view class="filter-card">
			<!-- 城市选择 + 搜索框 + 定位按钮 -->
			<view class="city-search-row flex-between">
				<!-- 城市选择器 -->
				<view class="city-select" @click="selectCity">
					<text class="city-text">{{ cityName }}</text>
					<text class="wlIcon wlIcon-fanhui4"></text>
				</view>
				<!-- 搜索输入框 -->
				<view class="search-input-box" @click="openSearch">
					<text class="search-icon">🔍</text>
					<text class="search-placeholder">位置/品牌/酒店</text>
				</view>
				<!-- 定位按钮 -->
				<view class="loc-btn" @click="openLocation">
					<text class="loc-icon">⚙</text>
				</view>
			</view>
			<view class="divider"></view>
			<!-- 定位提示条 -->
			<view class="location-tip flex-between" @click="goOpenSetting">
				<view class="tip-left flex-row">
					<text class="tip-icon">📍</text>
					<text class="tip-text">开启定位权限，发现附近优质酒店</text>
				</view>
				<text class="tip-link">去开启 ›</text>
			</view>

			<!-- 日期选择区域（入住日期 - 晚数 - 离店日期） -->
			<view class="date-row flex-between">
				<!-- 入住日期 -->
				<view class="date-block" @click="pickCheckIn">
					<text class="date-month">{{ checkInMonth }}月</text>
					<text class="date-num">{{ checkInDay }}</text>
					<text class="date-desc">{{ checkInLabel }}</text>
				</view>
				<!-- 入住晚数 -->
				<view class="night-tag">{{ nightCount }}晚</view>
				<!-- 离店日期 -->
				<view class="date-block" @click="pickCheckOut">
					<text class="date-month">{{ checkOutMonth }}月</text>
					<text class="date-num">{{ checkOutDay }}</text>
					<text class="date-desc">{{ checkOutLabel }}</text>
				</view>
			</view>
			<view class="divider"></view>

			<!-- 房间人数选择 + 价格星级筛选 -->
			<view class="guest-row flex-between">
				<!-- 房间人数选择器 -->
				<view class="guest-select flex-row" @click="selectGuest">
					<text>{{ roomDesc }}</text>
					<text class="wlIcon wlIcon-fanhui4 "></text>
				</view>
				<!-- 价格/星级筛选 -->
				<text class="filter-text">价格/星级</text>
			</view>
			<view class="divider"></view>

			<!-- 快捷标签横向滚动（亲子出游/环球影城等） -->
			<scroll-view scroll-x class="tag-scroll" :show-scrollbar="false">
				<view class="tag-list flex-row">
					<view v-for="(tag, idx) in hotTagList" :key="idx" class="tag-item" :class="{ active: activeTagIdx === idx }"
						@click="onTagClick(idx)">
						{{ tag }}
					</view>
				</view>
			</scroll-view>

			<!-- 搜索酒店按钮 -->
			<button class="search-btn" @click="searchHotel">搜索酒店</button>
		</view>

		<!-- ===== 最受欢迎酒店横向滚动列表 ===== -->
		<view class="hot-section">
			<view class="section-head flex-between">
				<text class="section-title">最受欢迎</text>
				<text class="more-link" @click="lookMoreHot">查看全部 ›</text>
			</view>
			<scroll-view scroll-x class="hot-card-scroll" :show-scrollbar="false">
				<view class="hot-card-list flex-row">
					<view v-for="(hotel, idx) in hotHotelList" :key="idx" class="hot-card" @click="goHotelDetail(hotel)">
						<!-- 收藏按钮（右上角心形） -->
						<view class="collect-btn" @click.stop="toggleCollect(hotel)">
							<text class="heart">{{ hotel.collect ? '❤️' : '' }}</text>
						</view>
						<!-- 酒店封面图片（暂时留空，后端接口就绪后替换） -->
						<image class="card-img" :src="hotel.img" mode="aspectFill"></image>
						<!-- 酒店信息 -->
						<view class="card-info">
							<text class="card-name">{{ hotel.name }}</text>
							<text class="card-address">{{ hotel.address }}</text>
							<view class="card-bottom flex-between">
								<text class="card-price">{{ hotel.price }}</text>
								<view class="score-box flex-row">
									<text class="score-star">⭐</text>
									<text class="score">{{ hotel.score }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>

		<!-- ===== 推荐给你列表 ===== -->
		<view class="recommend-section">
			<view class="section-head flex-between">
				<text class="section-title">推荐给你</text>
				<text class="more-link" @click="lookMoreRec">查看全部 ›</text>
			</view>
			<!-- 分类标签（所有/别墅/酒店/民宿） -->
			<scroll-view scroll-x class="cate-scroll" :show-scrollbar="false">
				<view class="cate-list flex-row">
					<view v-for="(cate, idx) in cateList" :key="idx" class="cate-item" :class="{ active: activeCateIdx === idx }"
						@click="onCateClick(idx)">
						{{ cate.label }}
					</view>
				</view>
			</scroll-view>
			<!-- 酒店列表 -->
			<view class="rec-list">
				<view v-for="(item, idx) in recHotelList" :key="idx" class="rec-item flex-row" @click="goHotelDetail(item)">
					<!-- 酒店封面图片（暂时留空，后端接口就绪后替换） -->
					<image class="rec-img" :src="item.img" mode="aspectFill"></image>
					<view class="rec-info flex-col ">
						<view class="rec-top flex-between">
							<text class="rec-name">{{ item.name }}</text>
							<view class="score-box flex-row">
								<text class="score-star">⭐</text>
								<text class="score">{{ item.score }}</text>
							</view>
						</view>
						<view class="rec-address flex-row">
							<text class="addr-icon">📍</text>
							<text class="addr-text">{{ item.address }}</text>
						</view>
						<text class="rec-price">{{ item.price }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 城市名称
			cityName: '北京',
			// Tab栏数据
			tabList: [
				{ label: '国内' },
				{ label: '国际' },
				{ label: '钟点房' },
				{ label: '民宿' },
				{ label: '短租' }
			],
			currentTab: 0,
			// 日期数据
			checkInMonth: 7,
			checkInDay: 20,
			checkInLabel: '今天',
			checkOutMonth: 7,
			checkOutDay: 21,
			checkOutLabel: '明天',
			nightCount: 1,
			// 房间人数
			roomCount: 1,
			adultCount: 2,
			childCount: 1,
			// 快捷标签
			hotTagList: ['亲子出游', '环球影城', '天安门广场', '鸟巢', '故宫'],
			activeTagIdx: 0,
			// 分类标签
			cateList: [
				{ label: '所有' },
				{ label: ' 别墅' },
				{ label: '🏨 酒店' },
				{ label: '🏢 民宿' }
			],
			activeCateIdx: 0,
			// 横向卡片【最受欢迎】酒店数据
			hotHotelList: [
				{
					name: '地平线撤退',
					address: '加利福尼亚州洛杉矶',
					price: '480元/晚',
					score: '4.5',
					collect: true,
					img: ''
				},
				{
					name: '阿斯特拉大酒店',
					address: '纽约州纽约市',
					price: '每晚300元',
					score: '4.5',
					collect: false,
					img: ''
				}
			],
			// 竖向【推荐给你】酒店列表
			recHotelList: [
				{
					name: '宁静沙滩',
					address: '檀香山，你好',
					price: '270元/晚',
					score: '4.0',
					img: ''
				},
				{
					name: '极乐套房',
					address: '加利福尼亚州圣地亚哥',
					price: '320元/晚',
					score: '3.8',
					img: ''
				}
			]
		}
	},
	computed: {
		// 房间人数描述
		roomDesc() {
			const parts = [`${this.roomCount}间房`, `${this.adultCount}成人`]
			if (this.childCount > 0) parts.push(`${this.childCount}儿童`)
			return parts.join(' ')
		}
	},
	methods: {
		// 切换tab
		switchTab(index) {
			this.currentTab = index
		},
		// 返回上一页
		goBack() {
			uni.navigateBack()
		},
		// 订单页面
		toOrder() {
			uni.navigateTo({ url: '/pages/order/order' })
		},
		// 搜索酒店
		searchHotel() {
			uni.showToast({ title: '搜索酒店' })
		},
		// 选择城市
		selectCity() {
			uni.navigateTo({ url: '/pages/travel/city-picker' })
		},
		// 打开搜索
		openSearch() {
			uni.navigateTo({ url: '/pages/travel/hotel/hotel-search' })
		},
		// 打开定位
		openLocation() {
			uni.getLocation({
				type: 'gcj02',
				success: (res) => {
					console.log('定位成功', res)
				},
				fail: () => {
					uni.showToast({ title: '定位失败', icon: 'none' })
				}
			})
		},
		// 去开启定位权限
		goOpenSetting() {
			uni.openSetting()
		},
		// 选择入住日期
		pickCheckIn() {
			uni.showToast({ title: '选择入住日期' })
		},
		// 选择离店日期
		pickCheckOut() {
			uni.showToast({ title: '选择离店日期' })
		},
		// 选择入住人数
		selectGuest() {
			uni.navigateTo({ url: '/pages/travel/hotel/room-picker' })
		},
		// 热门标签点击
		onTagClick(idx) {
			this.activeTagIdx = idx
		},
		// 分类标签点击
		onCateClick(idx) {
			this.activeCateIdx = idx
		},
		// 切换收藏
		toggleCollect(hotel) {
			hotel.collect = !hotel.collect
		},
		// 查看更多
		lookMoreHot() { },
		lookMoreRec() { 
			uni.navigateTo({ url: '/pages/travel/hotel/hotel-list' })
		},
		// 跳转酒店详情
		goHotelDetail(item) {
			console.log('跳转酒店详情:', item.name)
		}
	}
}
</script>

<style lang="scss" scoped>
page {
	background-color: #f7f9fc;
	margin: 0;
	padding: 0;
}

.flex-row {
	display: flex;
	flex-direction: row;
	align-items: center;
}

.flex-between {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
}

.flex-col {
	display: flex;
	flex-direction: column;
}

.page-wrap {
	min-height: 100vh;
}

/* ========== 顶部渐变导航栏 ========== */
.header-gradient {
	background: linear-gradient(90deg, #60d8f7, #3898f2);
	padding: 16rpx 32rpx;
	height: 200rpx;
}

.nav-bar {
	margin-bottom: 16rpx;

	.nav-btn {
		width: 88rpx;
		height: 88rpx;
		background: #fff;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.nav-icon {
			font-size: 32rpx;
			color: #333;
		}

		.btn-text {
			font-size: 20rpx;
			color: #333;
		}
	}

	.nav-title {
		font-size: 52rpx;
		font-weight: bold;
		color: #222;
	}
}

/* ========== 筛选白色卡片 ========== */
.filter-card {
	margin: 0;
	padding: 16rpx 24rpx;

}

/* Tab栏（渐变背景 + 选中白色圆角） */
.tab-wrap {
	display: flex;
	background: linear-gradient(180deg, #daeef9, #f9fbfe);
	border-radius: 36rpx 36rpx 0 0;
	margin-top: -50rpx;
	overflow: visible;

	.tab-item {
		flex: 1;
		text-align: center;
		padding: 10rpx;
		font-size: 34rpx;
		color: #667799;

		// 第一个tab左上圆角
		&:first-child {
			border-radius: 36rpx 0 0 0;
		}

		// 最后一个tab右上圆角
		&:last-child {
			border-radius: 0 36rpx 0 0;
		}

		&.active {
			background-color: #ffffff;
			color: #0066ff;
			font-weight: bold;
			border-radius: 24rpx 20rpx 0 0; // 选中状态圆角40rpx,比容器大4rpx
			margin-top: -12rpx;
			padding-top: 20rpx;
		}
	}
}

/* 城市选择 + 搜索框 + 定位 */
.city-search-row {
	margin-bottom: 32rpx;

	.city-select {
		.city-text {
			font-size: 40rpx;
			font-weight: 500;
			color: #222;
		}

		.arrow {
			font-size: 24rpx;
			color: #666;
			margin-left: 8rpx;
		}
	}

	.search-input-box {
		flex: 1;
		margin: 0 24rpx;
		background-color: #f2f3f6;
		border-radius: 16rpx;
		padding: 20rpx 24rpx;
		display: flex;
		align-items: center;

		.search-icon {
			font-size: 28rpx;
			color: #ccc;
			margin-right: 8rpx;
		}

		.search-placeholder {
			flex: 1;
			font-size: 30rpx;
			color: #bbb;
		}
	}

	.loc-btn {
		.loc-icon {
			font-size: 36rpx;
			color: #0066ff;
		}
	}
}

/* 定位提示条 */
.location-tip {
	background-color: #e8f4ff;
	border-radius: 16rpx;
	padding: 12rpx;
	margin-bottom: 36rpx;

	.tip-left {
		.tip-icon {
			font-size: 28rpx;
			color: #0066ff;
			margin-right: 8rpx;
		}

		.tip-text {
			font-size: 28rpx;
			color: #0052aa;
		}
	}

	.tip-link {
		font-size: 28rpx;
		color: #0066ff;
	}
}

/* 日期选择区域 */
.date-row {
	margin-bottom: 24rpx;

	.date-block {
		display: flex;
		align-items: baseline;

		.date-month {
			font-size: 28rpx;
			color: #666;
			margin-right: 4rpx;
		}

		.date-num {
			font-size: 48rpx;
			font-weight: bold;
			color: #222;
		}

		.date-desc {
			font-size: 30rpx;
			color: #999;
			margin-left: 8rpx;
		}
	}

	.night-tag {
		background-color: #f2f3f6;
		padding: 8rpx 24rpx;
		border-radius: 99rpx;
		font-size: 26rpx;
		color: #666;
	}
}

/* 房间人数 + 价格筛选 */
.guest-row {
	margin-bottom: 24rpx;

	.guest-select {
		font-size: 34rpx;
		color: #222;

		.arrow {
			font-size: 24rpx;
			color: #999;
			margin-left: 8rpx;
		}
	}

	.filter-text {
		font-size: 34rpx;
		color: #888;
	}
}

/* 分割线 */
.divider {
	width: 100%;
	height: 1rpx;
	background-color: #eeeeee;
	margin-bottom: 32rpx;
}

/* 快捷标签横向滚动 */
.tag-scroll {
	margin-bottom: 44rpx;
}

.tag-list {
	gap: 24rpx;

	.tag-item {
		padding: 14rpx 36rpx;
		background-color: #f2f3f6;
		border-radius: 24rpx;
		font-size: 30rpx;
		white-space: nowrap;
		color: #666;

		&.active {
			background-color: #ffe9ec;
			color: #ff6b7b;
		}
	}
}

/* 搜索酒店按钮 */
.search-btn {
	width: 100%;
	background-color: #0066ff;
	color: #fff;
	font-size: 40rpx;
	font-weight: bold;
	border-radius: 50rpx;
	// padding: 36rpx 0;
	border: none;
	box-shadow: 0 6rpx 16rpx rgba(0, 102, 255, 0.22);
}

/* ========== 最受欢迎模块 ========== */
.hot-section {
	background-color: #fff;
	padding: 0 32rpx 36rpx;
}

.section-head {
	padding: 36rpx 0 24rpx;

	.section-title {
		font-size: 40rpx;
		font-weight: bold;
		color: #222;
	}

	.more-link {
		font-size: 30rpx;
		color: #0066ff;
	}
}

.hot-card-scroll {
	width: 100%;
}

.hot-card-list {
	gap: 28rpx;
}

.hot-card {
	width: 540rpx;
	border-radius: 28rpx;
	overflow: hidden;
	position: relative;
	flex-shrink: 0;

	.collect-btn {
		position: absolute;
		top: 20rpx;
		right: 20rpx;
		width: 64rpx;
		height: 64rpx;
		background-color: rgba(255, 255, 255, 0.7);
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 2;

		.heart {
			font-size: 32rpx;
		}
	}

	.card-img {
		width: 100%;
		height: 340rpx;
		background-color: #f0f0f0;
	}

	.card-info {
		position: absolute;
		left: 0;
		bottom: 0;
		width: 100%;
		padding: 28rpx;
		background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
		color: #fff;

		.card-name {
			font-size: 36rpx;
			font-weight: bold;
			display: block;
		}

		.card-address {
			font-size: 28rpx;
			opacity: 0.9;
			display: block;
			margin: 8rpx 0 16rpx;
		}

		.card-price {
			font-size: 30rpx;
			font-weight: bold;
		}

		.score-box {
			.score {
				font-size: 28rpx;
				margin-left: 6rpx;
			}
		}
	}
}

/* ========== 推荐模块 ========== */
.recommend-section {
	background-color: #fff;
	margin-top: 20rpx;
	padding: 0 32rpx 100rpx;
}

.cate-scroll {
	margin-bottom: 32rpx;
}

.cate-list {
	gap: 24rpx;

	.cate-item {
		padding: 20rpx 44rpx;
		border-radius: 18rpx;
		background-color: #f2f3f6;
		font-size: 30rpx;
		white-space: nowrap;
		color: #666;

		&.active {
			background-color: #0066ff;
			color: #fff;
		}
	}
}

.rec-list {
	.rec-item {
		padding: 32rpx 0;
		border-bottom: 1rpx solid #eee;

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

		.rec-img {
			width: 240rpx;
			height: 200rpx;
			border-radius: 16rpx;
			flex-shrink: 0;
			background-color: #f0f0f0;
		}

		.rec-info {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			flex: 1;
			margin-left: 24rpx;
			height: 200rpx;

			.rec-top {
				display: flex;
				justify-content: space-between;
				margin-bottom: 12rpx;

				.rec-name {
					font-size: 34rpx;
					font-weight: bold;
					color: #222;
					flex: 1;
				}

				.score-box {
					flex-shrink: 0;
					display: flex;
					align-items: center;

					.score-star {
						font-size: 28rpx;
						margin-right: 6rpx;
					}

					.score {
						font-size: 30rpx;
						color: #222;
						font-weight: 500;
					}
				}
			}

			.rec-address {
				display: flex;
				align-items: center; // 垂直居中对齐
				justify-items: start;
				margin-bottom: 16rpx;

				.addr-icon {
					font-size: 22rpx;
					margin-right: 6rpx;
				}

				.addr-text {
					font-size: 26rpx;
					color: #999;
				}
			}

			.rec-price {
				display: flex;
				align-items: center;
				justify-content: flex-start;
				font-size: 34rpx;
				color: #0066ff;
				font-weight: bold;
			}
		}
	}
}
</style>