@extends('layouts.admin')

@section('title', 'Ruang Kelas')
@section('subtitle', 'Kelola data master ruang kelas')

@section('content')

<div class="row g-3">
    <div class="col-12 col-xl-4">
        <div class="panel">
            <div class="panel-head"><h3>Tambah Ruang</h3></div>
            <div class="panel-body">
                <form action="{{ route('admin.classrooms.store') }}" method="POST">
                    @csrf
                    <div class="mb-3">
                        <label class="form-label">Nama Ruang</label>
                        <input type="text" name="name" class="form-control" placeholder="Contoh: Ruang 6A" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Kode Ruang</label>
                        <input type="text" name="code" class="form-control" placeholder="Contoh: R-6A" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Kapasitas</label>
                        <input type="number" name="capacity" class="form-control" placeholder="Opsional">
                    </div>
                    <button type="submit" class="btn btn-brand w-100">
                        <i class="fa-solid fa-plus me-1"></i> Simpan
                    </button>
                </form>
            </div>
        </div>
    </div>

    <div class="col-12 col-xl-8">
        <div class="panel">
            <div class="panel-head">
                <h3>Daftar Ruang Kelas</h3>
                <span class="text-muted" style="font-size:.8rem;">{{ $classrooms->total() }} ruang</span>
            </div>
            <div class="table-responsive">
                <table class="table-modern">
                    <thead>
                        <tr><th>Kode</th><th>Nama</th><th>Kapasitas</th><th></th></tr>
                    </thead>
                    <tbody>
                        @forelse ($classrooms as $room)
                            <tr>
                                <td>{{ $room->code }}</td>
                                <td class="fw-semibold">{{ $room->name }}</td>
                                <td>{{ $room->capacity ?? '-' }}</td>
                                <td>
                                    <form action="{{ route('admin.classrooms.destroy', $room->id) }}" method="POST" onsubmit="return confirm('Hapus ruang ini?')">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn-soft-danger" title="Hapus"><i class="fa-solid fa-trash"></i></button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr><td colspan="4" class="text-center text-muted py-4">Belum ada ruang kelas.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="p-3">{{ $classrooms->links() }}</div>
        </div>
    </div>
</div>

@endsection
