@extends('layouts.admin')

@section('title', 'Jam Belajar')
@section('subtitle', 'Kelola data master jam belajar')

@section('content')

<div class="row g-3">
    <div class="col-12 col-xl-4">
        <div class="panel">
            <div class="panel-head"><h3>Tambah Jam Belajar</h3></div>
            <div class="panel-body">
                <form action="{{ route('admin.timeslots.store') }}" method="POST">
                    @csrf
                    <div class="mb-3">
                        <label class="form-label">Label</label>
                        <input type="text" name="label" class="form-control" placeholder="Contoh: Jam ke-1" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Jam Mulai</label>
                        <input type="time" name="start_time" class="form-control" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Jam Selesai</label>
                        <input type="time" name="end_time" class="form-control" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Urutan Tampil</label>
                        <input type="number" name="order" class="form-control" placeholder="Contoh: 1">
                    </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 Jam Belajar</h3>
                <span class="text-muted" style="font-size:.8rem;">{{ $timeslots->total() }} slot</span>
            </div>
            <div class="table-responsive">
                <table class="table-modern">
                    <thead>
                        <tr><th>Label</th><th>Mulai</th><th>Selesai</th><th></th></tr>
                    </thead>
                    <tbody>
                        @forelse ($timeslots as $slot)
                            <tr>
                                <td class="fw-semibold">{{ $slot->label }}</td>
                                <td>{{ \Illuminate\Support\Carbon::parse($slot->start_time)->format('H:i') }}</td>
                                <td>{{ \Illuminate\Support\Carbon::parse($slot->end_time)->format('H:i') }}</td>
                                <td>
                                    <form action="{{ route('admin.timeslots.destroy', $slot->id) }}" method="POST" onsubmit="return confirm('Hapus jam 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 jam belajar.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="p-3">{{ $timeslots->links() }}</div>
        </div>
    </div>
</div>

@endsection
