<?php
/**
 * 酒店查询预订模块 - 独立模块，不含婚宴酒店
 * 支持城市搜索、价格/星级筛选、详情查看、预订功能
 */
$pageTitle = '酒店查询预订';
require_once 'header.php';

// 获取搜索参数
$city = $_GET['city'] ?? '阳泉';
$checkin = $_GET['checkin'] ?? date('Y-m-d');
$checkout = $_GET['checkout'] ?? date('Y-m-d', strtotime('+1 day'));
$minPrice = $_GET['min_price'] ?? '';
$maxPrice = $_GET['max_price'] ?? '';
$star = $_GET['star'] ?? '';
$keyword = $_GET['keyword'] ?? '';
$sort = $_GET['sort'] ?? 'star';

// 热门城市列表
$hotCities = ['阳泉', '太原', '石家庄', '北京', '西安', '郑州', '济南', '天津'];

// 星级选项
$starOptions = [
    '5' => '五星级',
    '4' => '四星级',
    '3' => '三星级',
    '2' => '二星级',
    '0' => '经济型'
];

// 排序选项
$sortOptions = [
    'star' => '星级优先',
    'price' => '价格从低到高',
    'price_desc' => '价格从高到低',
    'rating' => '评分最高'
];
?>

<main class="site-main">
    <!-- 页面Banner -->
    <section class="page-banner hotel-banner">
        <div class="container">
            <h1><i class="fas fa-hotel"></i> 酒店查询预订</h1>
            <p>全国酒店在线查询，为出行提供舒适住宿选择</p>
        </div>
    </section>

    <!-- 搜索区域 -->
    <section class="hotel-search-section">
        <div class="container">
            <div class="hotel-search-box">
                <form method="get" action="hotel.php" class="hotel-search-form" id="hotelSearchForm">
                    <!-- 主搜索行 -->
                    <div class="search-main-row">
                        <div class="search-field field-city">
                            <label><i class="fas fa-map-marker-alt"></i> 目的地</label>
                            <input type="text" name="city" value="<?php echo htmlspecialchars($city); ?>" 
                                   placeholder="输入城市名称" class="search-input" id="cityInput">
                        </div>
                        <div class="search-field field-date">
                            <label><i class="fas fa-calendar-alt"></i> 入住日期</label>
                            <input type="date" name="checkin" value="<?php echo $checkin; ?>" 
                                   class="search-input" min="<?php echo date('Y-m-d'); ?>" id="checkinInput">
                        </div>
                        <div class="search-field field-date">
                            <label><i class="fas fa-calendar-check"></i> 离店日期</label>
                            <input type="date" name="checkout" value="<?php echo $checkout; ?>" 
                                   class="search-input" min="<?php echo date('Y-m-d', strtotime('+1 day')); ?>" id="checkoutInput">
                        </div>
                        <div class="search-field field-keyword">
                            <label><i class="fas fa-search"></i> 关键词</label>
                            <input type="text" name="keyword" value="<?php echo htmlspecialchars($keyword); ?>" 
                                   placeholder="酒店名称/品牌" class="search-input">
                        </div>
                        <div class="search-field field-btn">
                            <button type="submit" class="btn btn-primary btn-search">
                                <i class="fas fa-search"></i> 搜索酒店
                            </button>
                        </div>
                    </div>

                    <!-- 筛选行 -->
                    <div class="search-filter-row">
                        <div class="filter-group">
                            <label>价格范围：</label>
                            <input type="number" name="min_price" value="<?php echo $minPrice; ?>" 
                                   placeholder="最低" class="filter-input" min="0">
                            <span class="price-separator">-</span>
                            <input type="number" name="max_price" value="<?php echo $maxPrice; ?>" 
                                   placeholder="最高" class="filter-input" min="0">
                        </div>
                        
                        <div class="filter-group">
                            <label>酒店星级：</label>
                            <select name="star" class="filter-select">
                                <option value="">全部星级</option>
                                <?php foreach ($starOptions as $val => $label): ?>
                                <option value="<?php echo $val; ?>" <?php echo $star == $val ? 'selected' : ''; ?>>
                                    <?php echo $label; ?>
                                </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        
                        <div class="filter-group">
                            <label>排序方式：</label>
                            <select name="sort" class="filter-select">
                                <?php foreach ($sortOptions as $val => $label): ?>
                                <option value="<?php echo $val; ?>" <?php echo $sort == $val ? 'selected' : ''; ?>>
                                    <?php echo $label; ?>
                                </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        
                        <a href="hotel.php" class="btn-reset"><i class="fas fa-redo"></i> 重置</a>
                    </div>
                </form>

                <!-- 热门城市标签 -->
                <div class="hot-cities-tags">
                    <span class="hot-label"><i class="fas fa-fire"></i> 热门城市：</span>
                    <?php foreach ($hotCities as $c): ?>
                    <a href="?city=<?php echo urlencode($c); ?>&checkin=<?php echo $checkin; ?>&checkout=<?php echo $checkout; ?>" 
                       class="city-tag <?php echo $city === $c ? 'active' : ''; ?>">
                        <?php echo $c; ?>
                    </a>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    </section>

    <!-- 结果区域 -->
    <section class="hotel-results-section">
        <div class="container">
            <!-- 结果头部 -->
            <div class="results-header">
                <div class="results-title">
                    <h2><i class="fas fa-list-ul"></i> <?php echo htmlspecialchars($city); ?> 酒店</h2>
                    <span class="results-count" id="resultsCount">正在加载...</span>
                </div>
                <div class="results-info" id="resultsInfo"></div>
            </div>

            <!-- 酒店列表 -->
            <div class="hotel-list" id="hotelList">
                <div class="loading-state">
                    <i class="fas fa-spinner fa-spin"></i>
                    <p>正在搜索酒店...</p>
                </div>
            </div>

            <!-- 分页 -->
            <div class="hotel-pagination" id="hotelPagination"></div>
        </div>
    </section>

    <!-- 酒店详情弹窗 -->
    <div class="modal hotel-modal" id="hotelModal">
        <div class="modal-content hotel-modal-content">
            <div class="modal-header">
                <h3 id="modalHotelName">酒店详情</h3>
                <button class="modal-close" onclick="closeHotelModal()">&times;</button>
            </div>
            <div class="modal-body" id="modalHotelBody"></div>
        </div>
    </div>

    <!-- 预订弹窗 -->
    <div class="modal booking-modal" id="bookingModal">
        <div class="modal-content booking-modal-content">
            <div class="modal-header">
                <h3><i class="fas fa-calendar-check"></i> 预订确认</h3>
                <button class="modal-close" onclick="closeBookingModal()">&times;</button>
            </div>
            <div class="modal-body" id="bookingModalBody"></div>
        </div>
    </div>
</main>

<style>
/* 酒店Banner */
.hotel-banner {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* 搜索区域 */
.hotel-search-section {
    padding: 30px 0;
    background: #f5f7fa;
}

.hotel-search-box {
    background: #fff;
    border-radius: 16px;
    padding: 25px 30px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.search-main-row {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-field {
    flex: 1;
    min-width: 150px;
}

.field-city { flex: 1.5; min-width: 200px; }
.field-date { flex: 1; min-width: 160px; }
.field-keyword { flex: 1; min-width: 180px; }
.field-btn { flex: 0 0 auto; display: flex; align-items: flex-end; }

.search-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #555;
}

.search-field label i {
    color: #b64a2a;
    margin-right: 6px;
}

.search-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    transition: all 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: #b64a2a;
    box-shadow: 0 0 0 3px rgba(182,74,42,0.1);
}

.btn-search {
    padding: 12px 25px;
    font-size: 16px;
    border-radius: 10px;
}

/* 筛选行 */
.search-filter-row {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-group label {
    font-size: 14px;
    color: #666;
    white-space: nowrap;
}

.filter-input {
    width: 100px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.price-separator {
    color: #999;
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    min-width: 120px;
}

.btn-reset {
    color: #999;
    font-size: 14px;
    text-decoration: none;
    padding: 8px 15px;
    border-radius: 8px;
    transition: all 0.3s;
}

.btn-reset:hover {
    color: #b64a2a;
    background: rgba(182,74,42,0.05);
}

/* 热门城市 */
.hot-cities-tags {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px dashed #eee;
}

.hot-label {
    font-size: 14px;
    color: #666;
    margin-right: 10px;
}

.hot-label i {
    color: #e74c3c;
}

.city-tag {
    display: inline-block;
    padding: 6px 16px;
    margin: 4px;
    background: #f0f0f0;
    border-radius: 20px;
    font-size: 13px;
    color: #555;
    text-decoration: none;
    transition: all 0.3s;
}

.city-tag:hover,
.city-tag.active {
    background: #b64a2a;
    color: #fff;
    transform: translateY(-2px);
}

/* 结果区域 */
.hotel-results-section {
    padding: 30px 0 50px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.results-title h2 {
    font-size: 20px;
    color: #333;
    margin: 0;
}

.results-title h2 i {
    color: #b64a2a;
    margin-right: 8px;
}

.results-count {
    font-size: 14px;
    color: #999;
    margin-left: 15px;
}

/* 酒店卡片 */
.hotel-list {
    display: grid;
    gap: 20px;
}

.hotel-card {
    display: flex;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 15px rgba(0,0,0,0.06);
    transition: all 0.3s;
    cursor: pointer;
}

.hotel-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

.hotel-image {
    width: 280px;
    min-height: 220px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.hotel-image .hotel-icon {
    font-size: 60px;
    color: rgba(255,255,255,0.3);
}

.hotel-star-badge {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(255,255,255,0.95);
    color: #b64a2a;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.hotel-rating-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255,255,255,0.95);
    color: #27ae60;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 13px;
    font-weight: 600;
}

.hotel-info {
    flex: 1;
    padding: 20px 25px;
    display: flex;
    flex-direction: column;
}

.hotel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.hotel-name {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.hotel-brand {
    font-size: 13px;
    color: #999;
    margin-top: 4px;
}

.hotel-price-box {
    text-align: right;
}

.price-label {
    font-size: 12px;
    color: #999;
}

.price-value {
    font-size: 28px;
    font-weight: 700;
    color: #e74c3c;
}

.price-unit {
    font-size: 12px;
    color: #999;
}

.hotel-location {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    font-size: 13px;
    color: #666;
}

.hotel-location i {
    color: #b64a2a;
    margin-right: 4px;
}

.hotel-tags {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.hotel-tags .tag {
    padding: 4px 10px;
    background: #f0f7ff;
    color: #4a90d9;
    border-radius: 4px;
    font-size: 12px;
}

.hotel-rooms-preview {
    font-size: 13px;
    color: #999;
    margin-bottom: 15px;
}

.hotel-actions {
    display: flex;
    gap: 10px;
    margin-top: auto;
}

.hotel-actions .btn {
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 8px;
}

.btn-outline-primary {
    border: 2px solid #b64a2a;
    background: #fff;
    color: #b64a2a;
}

.btn-outline-primary:hover {
    background: #b64a2a;
    color: #fff;
}

/* 加载和空状态 */
.loading-state,
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: #999;
}

.loading-state i,
.empty-state i {
    font-size: 50px;
    margin-bottom: 20px;
    display: block;
}

.loading-state i { color: #b64a2a; }
.empty-state i { color: #ddd; }

/* 分页 */
.hotel-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 40px;
}

.page-btn {
    width: 40px;
    height: 40px;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    color: #555;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-btn:hover {
    border-color: #b64a2a;
    color: #b64a2a;
}

.page-btn.active {
    background: #b64a2a;
    border-color: #b64a2a;
    color: #fff;
}

.page-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-ellipsis {
    color: #999;
    padding: 0 5px;
}

/* 详情弹窗 */
.hotel-modal-content {
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.hotel-detail-header {
    padding: 40px 30px;
    color: #fff;
    text-align: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.detail-star-badge {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    padding: 8px 20px;
    border-radius: 25px;
    font-size: 14px;
    margin-bottom: 15px;
}

.detail-hotel-name {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 10px;
}

.detail-price-large {
    font-size: 42px;
    font-weight: 700;
}

.detail-price-large small {
    font-size: 18px;
    font-weight: 400;
    opacity: 0.8;
}

.hotel-detail-body {
    padding: 0;
}

.detail-section {
    padding: 25px 30px;
    border-bottom: 1px solid #eee;
}

.detail-section:last-child {
    border-bottom: none;
}

.detail-section-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
}

.detail-section-title i {
    color: #b64a2a;
    margin-right: 8px;
}

.detail-info-row {
    display: flex;
    margin-bottom: 12px;
    font-size: 14px;
}

.detail-info-label {
    width: 80px;
    color: #999;
}

.detail-info-value {
    flex: 1;
    color: #555;
}

.detail-info-value a {
    color: #b64a2a;
}

.facility-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.facility-tag {
    padding: 8px 16px;
    background: #f5f7fa;
    border-radius: 8px;
    font-size: 13px;
    color: #555;
}

.facility-tag i {
    color: #27ae60;
    margin-right: 6px;
}

/* 房型列表 */
.room-list {
    display: grid;
    gap: 12px;
}

.room-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f5f7fa;
    border-radius: 12px;
    transition: all 0.3s;
}

.room-card:hover {
    background: #eef2f7;
}

.room-info {
    display: flex;
    gap: 20px;
    align-items: center;
}

.room-name {
    font-weight: 600;
    color: #333;
}

.room-bed,
.room-area {
    font-size: 13px;
    color: #666;
}

.room-price-box {
    text-align: right;
}

.room-price {
    font-size: 22px;
    font-weight: 700;
    color: #e74c3c;
}

.room-unit {
    font-size: 12px;
    color: #999;
}

.room-book-btn {
    padding: 8px 20px;
    font-size: 13px;
    border-radius: 8px;
}

/* 预订弹窗 */
.booking-modal-content {
    max-width: 500px;
}

.booking-form {
    padding: 20px;
}

.booking-hotel-info {
    background: #f5f7fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.booking-row {
    margin-bottom: 15px;
}

.booking-row label {
    display: block;
    font-size: 14px;
    color: #555;
    margin-bottom: 8px;
}

.booking-row input,
.booking-row select {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.booking-total {
    background: #fff3e0;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    text-align: center;
}

.booking-total-price {
    font-size: 28px;
    font-weight: 700;
    color: #e74c3c;
}

.booking-submit-btn {
    width: 100%;
    padding: 15px;
    font-size: 16px;
    border-radius: 10px;
}

/* 响应式 */
@media (max-width: 768px) {
    .hotel-card {
        flex-direction: column;
    }
    
    .hotel-image {
        width: 100%;
        height: 180px;
    }
    
    .hotel-header {
        flex-direction: column;
    }
    
    .hotel-price-box {
        text-align: left;
        margin-top: 10px;
    }
    
    .search-main-row,
    .search-filter-row {
        flex-direction: column;
    }
    
    .search-field,
    .filter-group {
        width: 100%;
    }
    
    .room-card {
        flex-direction: column;
        gap: 15px;
    }
    
    .room-info {
        flex-wrap: wrap;
    }
}
</style>

<script>
// 搜索参数
let searchParams = {
    city: <?php echo json_encode($city); ?>,
    checkin: <?php echo json_encode($checkin); ?>,
    checkout: <?php echo json_encode($checkout); ?>,
    min_price: <?php echo json_encode($minPrice); ?>,
    max_price: <?php echo json_encode($maxPrice); ?>,
    star: <?php echo json_encode($star); ?>,
    keyword: <?php echo json_encode($keyword); ?>,
    sort: <?php echo json_encode($sort); ?>,
    page: 1,
    page_size: 10
};

// 加载酒店列表
function loadHotels() {
    const listContainer = document.getElementById('hotelList');
    listContainer.innerHTML = '<div class="loading-state"><i class="fas fa-spinner fa-spin"></i><p>正在搜索酒店...</p></div>';
    
    const query = new URLSearchParams(searchParams).toString();
    
    fetch('api/hotel.php?action=search&' + query)
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                renderHotelList(data.data);
                renderPagination(data.pagination);
                document.getElementById('resultsCount').textContent = '共 ' + data.pagination.total + ' 家酒店';
            } else {
                listContainer.innerHTML = '<div class="empty-state"><i class="fas fa-search"></i><p>' + (data.message || '未找到符合条件的酒店') + '</p><a href="hotel.php" class="btn btn-primary">查看全部酒店</a></div>';
                document.getElementById('resultsCount').textContent = '共 0 家酒店';
                document.getElementById('hotelPagination').innerHTML = '';
            }
        })
        .catch(error => {
            listContainer.innerHTML = '<div class="empty-state"><i class="fas fa-exclamation-triangle"></i><p>加载失败，请稍后重试</p></div>';
            console.error('Error:', error);
        });
}

// 渲染酒店列表
function renderHotelList(hotels) {
    const container = document.getElementById('hotelList');
    
    if (hotels.length === 0) {
        container.innerHTML = '<div class="empty-state"><i class="fas fa-hotel"></i><p>未找到符合条件的酒店</p></div>';
        return;
    }
    
    const gradients = [
        'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
        'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
        'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)',
        'linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)',
        'linear-gradient(135deg, #fa709a 0%, #fee140 100%)',
        'linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)'
    ];
    
    container.innerHTML = hotels.map((hotel, index) => {
        const gradient = gradients[index % gradients.length];
        const roomsPreview = hotel.rooms.slice(0, 3).map(r => r.name).join('、');
        
        return '<div class="hotel-card" onclick="showHotelDetail(\'' + hotel.id + '\')">' +
            '<div class="hotel-image" style="background: ' + gradient + '">' +
                '<i class="fas fa-hotel hotel-icon"></i>' +
                '<span class="hotel-star-badge">' + hotel.star_name + '</span>' +
                '<span class="hotel-rating-badge"><i class="fas fa-star"></i> ' + hotel.rating + '</span>' +
            '</div>' +
            '<div class="hotel-info">' +
                '<div class="hotel-header">' +
                    '<div>' +
                        '<h3 class="hotel-name">' + hotel.name + '</h3>' +
                        '<div class="hotel-brand">' + hotel.brand + ' · ' + hotel.review_count + '条评价</div>' +
                    '</div>' +
                    '<div class="hotel-price-box">' +
                        '<span class="price-label">最低价</span>' +
                        '<span class="price-value">¥' + hotel.price.min + '</span>' +
                        '<span class="price-unit">/晚</span>' +
                    '</div>' +
                '</div>' +
                '<div class="hotel-location">' +
                    '<span><i class="fas fa-map-marker-alt"></i> ' + hotel.address + '</span>' +
                    '<span><i class="fas fa-phone"></i> ' + hotel.phone + '</span>' +
                '</div>' +
                '<div class="hotel-tags">' +
                    hotel.tags.map(tag => '<span class="tag">' + tag + '</span>').join('') +
                '</div>' +
                '<div class="hotel-rooms-preview">' +
                    '<i class="fas fa-bed"></i> 房型：' + roomsPreview + ' 等' + hotel.rooms.length + '种' +
                '</div>' +
                '<div class="hotel-actions">' +
                    '<button class="btn btn-outline-primary" onclick="event.stopPropagation(); showHotelDetail(\'' + hotel.id + '\')">' +
                        '<i class="fas fa-info-circle"></i> 查看详情' +
                    '</button>' +
                    '<a href="tel:' + hotel.phone + '" class="btn btn-primary" onclick="event.stopPropagation()">' +
                        '<i class="fas fa-phone"></i> 电话预订' +
                    '</a>' +
                '</div>' +
            '</div>' +
        '</div>';
    }).join('');
}

// 渲染分页
function renderPagination(pagination) {
    const container = document.getElementById('hotelPagination');
    
    if (pagination.total_pages <= 1) {
        container.innerHTML = '';
        return;
    }
    
    let html = '';
    
    // 上一页
    if (pagination.page > 1) {
        html += '<button class="page-btn" onclick="goToPage(' + (pagination.page - 1) + ')"><i class="fas fa-chevron-left"></i></button>';
    } else {
        html += '<button class="page-btn disabled"><i class="fas fa-chevron-left"></i></button>';
    }
    
    // 页码
    for (let i = 1; i <= pagination.total_pages; i++) {
        if (i === 1 || i === pagination.total_pages || (i >= pagination.page - 2 && i <= pagination.page + 2)) {
            html += '<button class="page-btn ' + (i === pagination.page ? 'active' : '') + '" onclick="goToPage(' + i + ')">' + i + '</button>';
        } else if (i === pagination.page - 3 || i === pagination.page + 3) {
            html += '<span class="page-ellipsis">...</span>';
        }
    }
    
    // 下一页
    if (pagination.page < pagination.total_pages) {
        html += '<button class="page-btn" onclick="goToPage(' + (pagination.page + 1) + ')"><i class="fas fa-chevron-right"></i></button>';
    } else {
        html += '<button class="page-btn disabled"><i class="fas fa-chevron-right"></i></button>';
    }
    
    container.innerHTML = html;
}

// 跳转页面
function goToPage(page) {
    searchParams.page = page;
    loadHotels();
    window.scrollTo({ top: 300, behavior: 'smooth' });
}

// 显示酒店详情
function showHotelDetail(hotelId) {
    const modal = document.getElementById('hotelModal');
    const body = document.getElementById('modalHotelBody');
    const nameEl = document.getElementById('modalHotelName');
    
    body.innerHTML = '<div class="loading-state"><i class="fas fa-spinner fa-spin"></i><p>加载详情...</p></div>';
    modal.style.display = 'flex';
    
    fetch('api/hotel.php?action=detail&id=' + hotelId)
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                const hotel = data.data;
                nameEl.textContent = hotel.name;
                
                const gradients = [
                    'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
                    'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
                    'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)'
                ];
                const gradient = gradients[Math.floor(Math.random() * gradients.length)];
                
                body.innerHTML = 
                    '<div class="hotel-detail-header" style="background: ' + gradient + '">' +
                        '<div class="detail-star-badge">' + hotel.star_name + '</div>' +
                        '<div class="detail-hotel-name">' + hotel.name + '</div>' +
                        '<div class="detail-price-large">¥' + hotel.price.min + ' <small>起/晚</small></div>' +
                    '</div>' +
                    '<div class="hotel-detail-body">' +
                        '<div class="detail-section">' +
                            '<h4 class="detail-section-title"><i class="fas fa-info-circle"></i> 基本信息</h4>' +
                            '<div class="detail-info-row"><span class="detail-info-label">地址</span><span class="detail-info-value">' + hotel.address + '</span></div>' +
                            '<div class="detail-info-row"><span class="detail-info-label">电话</span><span class="detail-info-value"><a href="tel:' + hotel.phone + '">' + hotel.phone + '</a></span></div>' +
                            '<div class="detail-info-row"><span class="detail-info-label">品牌</span><span class="detail-info-value">' + hotel.brand + '</span></div>' +
                            '<div class="detail-info-row"><span class="detail-info-label">评分</span><span class="detail-info-value"><i class="fas fa-star" style="color:#f39c12"></i> ' + hotel.rating + ' (' + hotel.review_count + '条评价)</span></div>' +
                        '</div>' +
                        '<div class="detail-section">' +
                            '<h4 class="detail-section-title"><i class="fas fa-concierge-bell"></i> 酒店设施</h4>' +
                            '<div class="facility-tags">' +
                                hotel.facilities.map(f => '<span class="facility-tag"><i class="fas fa-check"></i> ' + f + '</span>').join('') +
                            '</div>' +
                        '</div>' +
                        '<div class="detail-section">' +
                            '<h4 class="detail-section-title"><i class="fas fa-bed"></i> 房型价格</h4>' +
                            '<div class="room-list">' +
                                hotel.rooms.map(room => 
                                    '<div class="room-card">' +
                                        '<div class="room-info">' +
                                            '<span class="room-name">' + room.name + '</span>' +
                                            '<span class="room-bed">' + room.bed + '</span>' +
                                            '<span class="room-area">' + room.area + '</span>' +
                                        '</div>' +
                                        '<div class="room-price-box">' +
                                            '<span class="room-price">¥' + room.price + '</span>' +
                                            '<span class="room-unit">/晚</span>' +
                                        '</div>' +
                                        '<button class="btn btn-primary room-book-btn" onclick="showBookingModal(\'' + hotel.id + '\', \'' + room.name + '\', ' + room.price + ')">' +
                                            '<i class="fas fa-calendar-check"></i> 预订' +
                                        '</button>' +
                                    '</div>'
                                ).join('') +
                            '</div>' +
                        '</div>' +
                        '<div class="detail-section">' +
                            '<h4 class="detail-section-title"><i class="fas fa-file-alt"></i> 入住政策</h4>' +
                            '<div class="detail-info-row"><span class="detail-info-label">入住</span><span class="detail-info-value">' + hotel.policies.checkin + '</span></div>' +
                            '<div class="detail-info-row"><span class="detail-info-label">离店</span><span class="detail-info-value">' + hotel.policies.checkout + '</span></div>' +
                            '<div class="detail-info-row"><span class="detail-info-label">取消</span><span class="detail-info-value">' + hotel.policies.cancel + '</span></div>' +
                            '<div class="detail-info-row"><span class="detail-info-label">儿童</span><span class="detail-info-value">' + hotel.policies.children + '</span></div>' +
                            '<div class="detail-info-row"><span class="detail-info-label">宠物</span><span class="detail-info-value">' + hotel.policies.pets + '</span></div>' +
                        '</div>' +
                        '<div class="detail-section">' +
                            '<h4 class="detail-section-title"><i class="fas fa-map-signs"></i> 周边信息</h4>' +
                            '<p style="color:#555;font-size:14px">' + hotel.nearby.join('、') + '</p>' +
                            '<p style="color:#666;font-size:13px;margin-top:10px">' + hotel.description + '</p>' +
                        '</div>' +
                    '</div>';
            } else {
                body.innerHTML = '<div class="empty-state"><i class="fas fa-exclamation-circle"></i><p>' + data.message + '</p></div>';
            }
        });
}

// 显示预订弹窗
function showBookingModal(hotelId, roomName, roomPrice) {
    const modal = document.getElementById('bookingModal');
    const body = document.getElementById('bookingModalBody');
    
    const checkin = searchParams.checkin;
    const checkout = searchParams.checkout;
    const days = Math.ceil((new Date(checkout) - new Date(checkin)) / 86400000);
    const totalPrice = roomPrice * days;
    
    body.innerHTML = 
        '<div class="booking-form">' +
            '<div class="booking-hotel-info">' +
                '<p><strong>房型：</strong>' + roomName + '</p>' +
                '<p><strong>单价：</strong>¥' + roomPrice + '/晚</p>' +
                '<p><strong>入住：</strong>' + checkin + ' ~ ' + checkout + ' (' + days + '晚)</p>' +
            '</div>' +
            '<div class="booking-total">' +
                '<p style="margin-bottom:5px;color:#666">订单总额</p>' +
                '<span class="booking-total-price">¥' + totalPrice + '</span>' +
            '</div>' +
            '<div class="booking-row">' +
                '<label>入住人姓名</label>' +
                '<input type="text" placeholder="请输入入住人姓名" id="guestName">' +
            '</div>' +
            '<div class="booking-row">' +
                '<label>联系电话</label>' +
                '<input type="tel" placeholder="请输入联系电话" id="guestPhone">' +
            '</div>' +
            '<div class="booking-row">' +
                '<label>特殊要求</label>' +
                '<input type="text" placeholder="如有特殊要求请填写" id="guestRequest">' +
            '</div>' +
            '<button class="btn btn-primary booking-submit-btn" onclick="submitBooking(\'' + hotelId + '\', \'' + roomName + '\')">' +
                '<i class="fas fa-check"></i> 确认预订' +
            '</button>' +
            '<p style="text-align:center;color:#999;font-size:12px;margin-top:15px">' +
                '<i class="fas fa-info-circle"></i> 预订成功后请联系酒店确认' +
            '</p>' +
        '</div>';
    
    modal.style.display = 'flex';
}

// 提交预订（模拟）
function submitBooking(hotelId, roomName) {
    const guestName = document.getElementById('guestName').value;
    const guestPhone = document.getElementById('guestPhone').value;
    
    if (!guestName || !guestPhone) {
        alert('请填写入住人姓名和联系电话');
        return;
    }
    
    // 这里可以调用真实的预订API
    alert('预订请求已提交！\n\n请联系酒店电话确认预订详情。\n\n感谢您的预订！');
    closeBookingModal();
}

// 关闭详情弹窗
function closeHotelModal() {
    document.getElementById('hotelModal').style.display = 'none';
}

// 关闭预订弹窗
function closeBookingModal() {
    document.getElementById('bookingModal').style.display = 'none';
}

// 点击弹窗外部关闭
window.onclick = function(event) {
    const hotelModal = document.getElementById('hotelModal');
    const bookingModal = document.getElementById('bookingModal');
    
    if (event.target === hotelModal) {
        hotelModal.style.display = 'none';
    }
    if (event.target === bookingModal) {
        bookingModal.style.display = 'none';
    }
}

// 初始化加载
document.addEventListener('DOMContentLoaded', function() {
    loadHotels();
    
    // 表单提交时重置页码
    document.getElementById('hotelSearchForm').addEventListener('submit', function() {
        searchParams.page = 1;
    });
});

// 日期联动
document.getElementById('checkinInput').addEventListener('change', function() {
    const checkin = this.value;
    const checkoutInput = document.getElementById('checkoutInput');
    const minCheckout = new Date(checkin);
    minCheckout.setDate(minCheckout.getDate() + 1);
    checkoutInput.min = minCheckout.toISOString().split('T')[0];
    if (new Date(checkoutInput.value) <= new Date(checkin)) {
        checkoutInput.value = minCheckout.toISOString().split('T')[0];
    }
});
</script>

<?php require_once 'footer.php'; ?>