    
    
    <?php $__env->startSection('content'); ?>
    
    
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h3 class="fw-bold mb-1">Rooms</h3>
            <p class="text-muted mb-0">Manage rooms, images, amenities & pricing</p>
        </div>
        <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addRoom">
            + Add Room
        </button>
    </div>
    
    <?php if(session('success')): ?>
    <div class="alert alert-success alert-dismissible fade show">
        <?php echo e(session('success')); ?>

        <button class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    <?php endif; ?>
    
    
    <div class="row g-4">
    <?php $__empty_1 = true; $__currentLoopData = $rooms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $room): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
    <div class="col-md-4">
        <div class="card border-0 shadow-sm h-100 room-card">
            <div class="card-body">
    
                <h5 class="fw-bold mb-1">Room #<?php echo e($room->room_number); ?></h5>
                <p class="text-muted small"><?php echo e($room->category->name); ?></p>
    
              <div class="mb-2">
    
        
        <span class="badge bg-light text-dark">
            Normal: ₹ <?php echo e($room->price_per_night); ?>/night
        </span>
    
        
        <span class="badge bg-success">
            Today: ₹ <?php echo e($room->getPriceForDate(now()->toDateString())); ?>/night
        </span>
    
        <span class="badge bg-light text-dark">
            <?php echo e($room->max_guests); ?> Guests
        </span>
    
    </div>
    
                <span class="badge
                    <?php if($room->status=='available'): ?> bg-success
                    <?php elseif($room->status=='maintenance'): ?> bg-warning
                    <?php else: ?> bg-danger
                    <?php endif; ?>">
                    <?php echo e(ucfirst($room->status)); ?>

                </span>
    
                
                <div class="mt-3">
                    <?php $__currentLoopData = $room->amenities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $a): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <span class="badge bg-light text-dark"><?php echo e($a->name); ?></span>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
    
                
                <div class="d-flex justify-content-between mt-4">
                    <div class="btn-group">
                        <button class="btn btn-sm btn-outline-primary"
                                data-bs-toggle="modal"
                                data-bs-target="#editRoom<?php echo e($room->id); ?>">
                            Edit
                        </button>
    
                        <button class="btn btn-sm btn-outline-secondary"
                                data-bs-toggle="modal"
                                data-bs-target="#imageRoom<?php echo e($room->id); ?>">
                            Images
                        </button>
    
                        <button class="btn btn-sm btn-outline-dark"
                                data-bs-toggle="modal"
                                data-bs-target="#rateRoom<?php echo e($room->id); ?>">
                            Rates
                        </button>
                       <button class="btn btn-sm btn-outline-info"
        data-bs-toggle="modal"
        data-bs-target="#yearCalendar<?php echo e($room->id); ?>"
        onclick="openYearCalendar(<?php echo e($room->id); ?>)">
    Year Calendar
</button>


                    </div>
    
                    <form method="POST" action="<?php echo e(route('rooms.destroy',$room->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('DELETE'); ?>
                        <button class="btn btn-sm btn-outline-danger"
                                onclick="return confirm('Delete room?')">
                            Delete
                        </button>
                    </form>
                </div>
    
            </div>
        </div>
    </div>
    
<div class="modal fade" id="yearCalendar<?php echo e($room->id); ?>">
    <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
        <div class="modal-content">

            <div class="modal-header">
                <h5 class="modal-title">
                    Year Price Calendar – Room <?php echo e($room->room_number); ?>

                </h5>
                <button class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">

                
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <button class="btn btn-outline-secondary btn-sm"
                            onclick="changeYear(<?php echo e($room->id); ?>, -1)">
                        ‹ Prev Year
                    </button>

                    <h4 id="yearTitle<?php echo e($room->id); ?>"></h4>

                    <button class="btn btn-outline-secondary btn-sm"
                            onclick="changeYear(<?php echo e($room->id); ?>, 1)">
                        Next Year ›
                    </button>
                </div>

                
                <div id="yearGrid<?php echo e($room->id); ?>" class="row g-4"></div>

            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="addRoom">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <form class="modal-content" method="POST" action="<?php echo e(route('rooms.store')); ?>">
            <?php echo csrf_field(); ?>

            <div class="modal-header">
                <h5>Add Room</h5>
                <button class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <div class="row">

                    <div class="col-md-6 mb-3">
                        <label class="form-label fw-semibold">Room Number</label>
                        <input type="text" name="room_number" class="form-control" required>
                    </div>

                    <div class="col-md-6 mb-3">
                        <label class="form-label fw-semibold">Category</label>
                        <select name="category_id" class="form-select" required>
                            <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($cat->id); ?>"><?php echo e($cat->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    <div class="col-md-6 mb-3">
                        <label class="form-label fw-semibold">Price / Night</label>
                        <input type="number" name="price_per_night" class="form-control" required>
                    </div>

                    <div class="col-md-6 mb-3">
                        <label class="form-label fw-semibold">Max Guests</label>
                        <input type="number" name="max_guests" class="form-control" required>
                    </div>

                    <div class="col-md-12 mb-3">
                        <label class="form-label fw-semibold">Amenities</label>
                        <div class="row">
                            <?php $__currentLoopData = $amenities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $a): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="col-md-4">
                                <div class="form-check">
                                    <input class="form-check-input"
                                           type="checkbox"
                                           name="amenities[]"
                                           value="<?php echo e($a->id); ?>">
                                    <label class="form-check-label"><?php echo e($a->name); ?></label>
                                </div>
                            </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    </div>

                    <div class="col-md-12 mb-3">
                        <label class="form-label fw-semibold">Status</label>
                        <select name="status" class="form-select">
                            <option value="available">Available</option>
                            <option value="maintenance">Maintenance</option>
                        </select>
                    </div>

                </div>
            </div>

            <div class="modal-footer">
                <button class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
                <button class="btn btn-primary">Save Room</button>
            </div>
        </form>
    </div>
</div>
    
    <?php echo $__env->make('admin.rooms.partials.edit', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
    
    
    <div class="modal fade" id="imageRoom<?php echo e($room->id); ?>">
        <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable">
            <form class="modal-content"
                  method="POST"
                  enctype="multipart/form-data"
                  action="<?php echo e(route('rooms.images.store',$room->id)); ?>">
                <?php echo csrf_field(); ?>
    
                <div class="modal-header">
                    <h5>Room Images – <?php echo e($room->room_number); ?></h5>
                    <button class="btn-close" data-bs-dismiss="modal"></button>
                </div>
    
                <div class="modal-body">
                    <input type="file" name="images[]" class="form-control mb-3" multiple>
    
                    <div class="row g-3">
                        <?php $__currentLoopData = $room->images; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $img): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="col-md-3 col-6">
                            <div class="room-image-box">
                                <img src="<?php echo e(url('uploads/rooms/'.$img->image)); ?>">
                                <button type="button"
                                        class="delete-btn"
                                        onclick="deleteImage(<?php echo e($img->id); ?>)">×</button>
                            </div>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>
    
                <div class="modal-footer">
                    <button class="btn btn-light" data-bs-dismiss="modal">Close</button>
                    <button class="btn btn-primary">Upload</button>
                </div>
            </form>
        </div>
    </div>
    
    
    <div class="modal fade" id="rateRoom<?php echo e($room->id); ?>">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <form class="modal-content"
                  method="POST"
                  action="<?php echo e(route('rooms.rates.store',$room->id)); ?>">
                <?php echo csrf_field(); ?>
    
                <div class="modal-header">
                    <h5>Room Rates – Room <?php echo e($room->room_number); ?></h5>
                    <button class="btn-close" data-bs-dismiss="modal"></button>
                </div>
    
<div class="modal-body">

    
    <div class="border rounded p-3 mb-4 bg-light">

        <h6 class="fw-bold mb-3">Add / Update Rate</h6>

        <div class="row mb-3">
            <div class="col-md-6">
                <label>Start Date</label>
                <input type="date" name="start_date" class="form-control" required>
            </div>
            <div class="col-md-6">
                <label>End Date</label>
                <input type="date" name="end_date" class="form-control" required>
            </div>
        </div>

        <div class="row">
            <?php
                $days = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday'];
            ?>

            <?php $__currentLoopData = $days; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $day): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="col-md-4 mb-3">
                <label class="text-capitalize"><?php echo e($day); ?></label>
                <input type="number"
                       name="<?php echo e($day); ?>_price"
                       class="form-control"
                       placeholder="Normal price if empty">
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>

    
    <h6 class="fw-bold mb-2">Existing Rate Records</h6>

    <?php if($room->priceRules->count()): ?>
        <div class="table-responsive">
            <table class="table table-bordered table-sm align-middle">
                <thead class="table-light">
                    <tr>
                        <th>Date Range</th>
                        <th>Mon</th>
                        <th>Tue</th>
                        <th>Wed</th>
                        <th>Thu</th>
                        <th>Fri</th>
                        <th>Sat</th>
                        <th>Sun</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $room->priceRules; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rule): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td>
                            <?php echo e(\Carbon\Carbon::parse($rule->start_date)->format('d M Y')); ?>

                            <br>
                            <small class="text-muted">
                                to <?php echo e(\Carbon\Carbon::parse($rule->end_date)->format('d M Y')); ?>

                            </small>
                        </td>
                        <td><?php echo e($rule->monday_price ?? '-'); ?></td>
                        <td><?php echo e($rule->tuesday_price ?? '-'); ?></td>
                        <td><?php echo e($rule->wednesday_price ?? '-'); ?></td>
                        <td><?php echo e($rule->thursday_price ?? '-'); ?></td>
                        <td><?php echo e($rule->friday_price ?? '-'); ?></td>
                        <td><?php echo e($rule->saturday_price ?? '-'); ?></td>
                        <td><?php echo e($rule->sunday_price ?? '-'); ?></td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
    <?php else: ?>
        <p class="text-muted">No special rates added yet.</p>
    <?php endif; ?>

</div>

    
                <div class="modal-footer">
                    <button class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
                    <button class="btn btn-primary">Save Rates</button>
                </div>
            </form>
        </div>
    </div>
    
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
    <div class="col-12 text-center py-5">
        <h5 class="text-muted">No rooms found</h5>
    </div>
    <?php endif; ?>
    </div>
    
    
    <style>
    .room-card { transition:.3s }
    .room-card:hover {
        transform: translateY(-6px);
        box-shadow: 0 15px 35px rgba(0,0,0,.08);
    }
    .room-image-box {
        position: relative;
        height: 140px;
        overflow: hidden;
        border-radius: 10px;
    }
    .room-image-box img {
        width:100%;
        height:100%;
        object-fit:cover;
    }
    .delete-btn {
        position:absolute;
        top:6px;
        right:6px;
        width:26px;
        height:26px;
        border:none;
        border-radius:50%;
        background:rgba(220,53,69,.9);
        color:#fff;
    }
    .month-box {
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 8px;
    background: #fff;
}

.month-title {
    text-align: center;
    font-weight: 600;
    margin-bottom: 6px;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.day-head {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    color: #6c757d;
}

.day-cell {
    border: 1px solid #eee;
    border-radius: 5px;
    padding: 3px;
    font-size: 10px;
    text-align: center;
}

.day-cell .price {
    font-size: 10px;
    color: #198754;
}

.day-cell.today {
    border: 2px solid #0d6efd;
}

    </style>
<script>
window.roomPrices = {};
let calendarYear = {};

// ---------- PRICE MAP ----------
<?php $__currentLoopData = $rooms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $room): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
window.roomPrices[<?php echo e($room->id); ?>] = {
    default: <?php echo e($room->price_per_night); ?>,
    <?php
        $start = now()->startOfYear();
        $end   = now()->endOfYear();
    ?>
    <?php for($d = $start->copy(); $d <= $end; $d->addDay()): ?>
        "<?php echo e($d->toDateString()); ?>": <?php echo e($room->getPriceForDate($d->toDateString())); ?>,
    <?php endfor; ?>
};
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

// ---------- OPEN CALENDAR ----------
function openYearCalendar(roomId) {
    calendarYear[roomId] = new Date().getFullYear(); // ✅ FIX NaN
    renderYear(roomId);
}

// ---------- CHANGE YEAR ----------
function changeYear(roomId, step) {
    calendarYear[roomId] += step;
    renderYear(roomId);
}

// ---------- RENDER YEAR ----------
function renderYear(roomId) {

    const year = calendarYear[roomId];
    document.getElementById('yearTitle' + roomId).innerText = year;

    const container = document.getElementById('yearGrid' + roomId);
    container.innerHTML = '';

    const monthNames = [
        "January","February","March","April","May","June",
        "July","August","September","October","November","December"
    ];

    const days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];

    for (let m = 0; m < 12; m++) {

        let firstDay = new Date(year, m, 1).getDay();
        let daysInMonth = new Date(year, m + 1, 0).getDate();

        let html = `
        <div class="col-md-3">
            <div class="month-box">
                <div class="month-title">${monthNames[m]}</div>
                <div class="month-grid">
                    ${days.map(d => `<div class="day-head">${d}</div>`).join('')}
        `;

        // Empty cells before first day
        for (let i = 0; i < firstDay; i++) {
            html += `<div></div>`;
        }

        // Days
        for (let d = 1; d <= daysInMonth; d++) {

            let dateStr =
                year + '-' +
                String(m + 1).padStart(2, '0') + '-' +
                String(d).padStart(2, '0');

            let price = getRoomPrice(roomId, dateStr);

            let isToday =
                new Date().toDateString() ===
                new Date(year, m, d).toDateString();

            html += `
            <div class="day-cell ${isToday ? 'today' : ''}">
                ${d}
                <div class="price">₹${price}</div>
            </div>`;
        }

        html += `</div></div></div>`;
        container.insertAdjacentHTML('beforeend', html);
    }
}

// ---------- PRICE RESOLVER ----------
function getRoomPrice(roomId, date) {
    return window.roomPrices[roomId][date]
        ?? window.roomPrices[roomId].default;
}
</script>


   <script>
function deleteImage(id){
    if(!confirm('Delete image?')) return;

    fetch("<?php echo e(url('admin/room-images')); ?>/" + id, {
        method: "POST",
        headers: {
            "X-CSRF-TOKEN": "<?php echo e(csrf_token()); ?>",
            "X-HTTP-Method-Override": "DELETE",
            "Accept": "application/json"
        }
    })
    .then(res => res.json())
    .then(data => {
        if(data.success){
            location.reload();
        } else {
            alert('Failed to delete image');
        }
    });
}
</script>

    <?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home2/jitrealx/public_html/hotelbooking/resources/views/admin/rooms/index.blade.php ENDPATH**/ ?>