@extends('layouts.app')

@section('content')
    <div class="container-fluid p-4">
        <div class="card shadow-sm p-3">
            <h4 class="fw-bold" style="color: #063986;">Data Kamar</h4>
            <div class="d-flex justify-content-between align-items-center mb-3">
                <!-- Tombol Tambah Data -->
                <a href="{{ route('admin.createroom') }}" class="btn text-white"
                    style="background: linear-gradient(135deg, #8AC0DF, #48499B); border: none;">
                    <i class="bi bi-plus-circle"></i> Tambah Kamar
                </a>

                <!-- Form Pencarian -->
                <form method="GET" action="{{ route('admin.rooms') }}" class="d-flex">
                    <input type="text" name="search" class="form-control form-control-sm me-2"
                        placeholder="Cari kamar..." value="{{ request()->search }}" style="max-width: 200px;">
                    <button type="submit" class="btn btn-outline-secondary btn-sm">Cari</button>
                </form>
            </div>

            <!-- Tabel Data Kamar -->
            <div class="table-responsive">
                <table class="table table-bordered text-center">
                    <thead class="table-primary">
                        <tr>
                            <th>No</th>
                            <th>Nomor Kamar</th>
                            <th>Tipe Kamar</th>
                            <th>Harga</th>
                            <th>Status</th>
                            <th>Lantai</th>
                            <th>Fasilitas</th>
                            <th>Foto</th>
                            <th>Deskripsi</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($rooms as $room)
                            <tr>
                                <td>{{ ($rooms->currentPage() - 1) * $rooms->perPage() + $loop->iteration }}</td>
                                <td>{{ $room->room_number }}</td>
                                <td>{{ $room->room_type }}</td>
                                <td>Rp {{ number_format((int) $room->harga, 0, ',', '.') }}</td>
                                <td>{{ ucfirst($room->status) }}</td>
                                <td>{{ $room->lantai }}</td>
                                <td>{{ $room->fasilitas }}</td>
                                <td>
                                    @if($room->foto)
                                        <img src="{{ asset('assets/admin/' . $room->foto) }}" alt="Foto Kamar" width="80" class="rounded">
                                    @else
                                        <span class="text-muted">Tidak ada foto</span>
                                    @endif
                                </td>
                                <td>{{ $room->deskripsi }}</td>
                                <td>
                                    <a href="{{ route('admin.editroom', ['id_kamar' => $room->id_kamar]) }}">
                                        <i class="bi bi-pencil-square"></i>
                                    </a>
                                    <a href="{{ route('admin.deleteroom', ['id_kamar' => $room->id_kamar]) }}" class="text-danger"
                                        onclick="return confirm('Apakah Anda yakin ingin menghapus kamar ini?');">
                                        <i class="bi bi-trash-fill"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>

                <!-- Pagination -->
                <div class="mt-3 d-flex justify-content-center">
                    {{ $rooms->withQueryString()->links() }}
                </div>
            </div>

        </div>
    </div>
@endsection
