@extends('admin.layout')

@section('title', 'Edit Booking')

@section('content')
    <h1 class="h4 fw-bold mb-4">Edit Booking</h1>

    <form action="{{ url('/booking-admin/' . $room . '/bookings/' . $booking->id) }}" method="POST" class="card shadow-sm p-4">
        @csrf
        @method('PUT')

        <div class="mb-3">
            <label class="form-label">Nama PIC</label>
            <input type="text" name="pic" 
                   value="{{ old('pic', $booking->pic) }}"
                   class="form-control" required>
        </div>

        <div class="row">
            <div class="col-md-6 mb-3">
                <label class="form-label">Tanggal</label>
                <input type="date" name="date" id="booking-date"
                       value="{{ old('date', $booking->date) }}"
                       class="form-control" required>
            </div>
            <div class="col-md-3 mb-3">
                <label class="form-label">Jam Mulai</label>
                <input type="time" name="start_time" 
                       value="{{ old('start_time', $booking->start_time) }}"
                       class="form-control" required>
            </div>
            <div class="col-md-3 mb-3">
                <label class="form-label">Jam Selesai</label>
                <input type="time" name="end_time" 
                       value="{{ old('end_time', $booking->end_time) }}"
                       class="form-control" required>
            </div>
        </div>

        {{-- Departemen --}}
        <div class="mb-3">
            <label class="form-label">Departemen</label>
            <select name="department" class="form-control" required>
                <option value="">-- Pilih Departemen --</option>
                <option value="IT" {{ old('department', $booking->department) == 'IT' ? 'selected' : '' }}>IT</option>
                <option value="Finance" {{ old('department', $booking->department) == 'Finance' ? 'selected' : '' }}>Finance & Accounting</option>
                <option value="Casting" {{ old('department', $booking->department) == 'Casting' ? 'selected' : '' }}>Casting</option>
                <option value="Casting Engineering" {{ old('department', $booking->department) == 'Casting Engineering' ? 'selected' : '' }}>Casting Engineering</option>
                <option value="Finishing" {{ old('department', $booking->department) == 'Finishing' ? 'selected' : '' }}>Finishing</option>
                <option value="HSE" {{ old('department', $booking->department) == 'HSE' ? 'selected' : '' }}>HSE</option>
                <option value="Machining" {{ old('department', $booking->department) == 'Machining' ? 'selected' : '' }}>Machining</option>
                <option value="Machining Engineering" {{ old('department', $booking->department) == 'Machining Engineering' ? 'selected' : '' }}>Machining Engineering</option>
                <option value="Maintenance" {{ old('department', $booking->department) == 'Maintenance' ? 'selected' : '' }}>Maintenance</option>
                <option value="PGA" {{ old('department', $booking->department) == 'PGA' ? 'selected' : '' }}>PGA</option>
                <option value="PPSC" {{ old('department', $booking->department) == 'PPSC' ? 'selected' : '' }}>PPSC</option>
                <option value="Purchasing" {{ old('department', $booking->department) == 'Purchasing' ? 'selected' : '' }}>Purchasing</option>
                <option value="Quality" {{ old('department', $booking->department) == 'Quality' ? 'selected' : '' }}>Quality</option>
                <option value="Sales" {{ old('department', $booking->department) == 'Sales' ? 'selected' : '' }}>Sales</option>
                <option value="New Model" {{ old('department', $booking->department) == 'New Model' ? 'selected' : '' }}>New Model</option>
            </select>
        </div>

        <div class="mb-3">
            <label class="form-label">Keterangan</label>
            <textarea name="keterangan" rows="3"
                      class="form-control">{{ old('keterangan', $booking->keterangan) }}</textarea>
        </div>

        <div class="d-flex gap-2">
            <button type="submit" class="btn btn-success">
                <i class="bi bi-check-circle"></i> Simpan Perubahan
            </button>
            <a href="{{ url('/booking-admin/' . $room . '/bookings') }}" class="btn btn-secondary">
                <i class="bi bi-arrow-left"></i> Kembali
            </a>
        </div>
    </form>
@endsection

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const today = new Date();
        const year = today.getFullYear();
        const month = String(today.getMonth() + 1).padStart(2, '0');
        const day = String(today.getDate()).padStart(2, '0');
        const todayString = `${year}-${month}-${day}`;

        const dateInput = document.getElementById('booking-date');
        if (dateInput) {
            dateInput.min = todayString;
        }
    });
</script>
