<?php $__env->startSection('content'); ?>
<div class="container py-10">
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="text-center mb-6">
                <h2 class="mb-2">Form Pelaporan Kerusakan</h2>
                <p class="text-muted">Silakan isi detail kerusakan barang atau fasilitas agar segera kami tindak lanjuti.</p>
            </div>
            
            <div class="card shadow-sm">
                <div class="card-body p-6">
                    <form action="<?php echo e(route('public.tickets.store')); ?>" method="POST" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <div class="row g-4">
                            <div class="col-md-6">
                                <label class="form-label" for="reporter_name">Nama Pelapor <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="reporter_name" name="reporter_name" placeholder="Masukkan nama lengkap" required value="<?php echo e(old('reporter_name')); ?>">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="reporter_email">Alamat Email <span class="text-danger">*</span></label>
                                <input type="email" class="form-control" id="reporter_email" name="reporter_email" placeholder="contoh@email.com" required value="<?php echo e(old('reporter_email')); ?>">
                                <div class="form-text">Digunakan untuk mengirimkan notifikasi progres perbaikan.</div>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="maintainable_type">Kategori Objek <span class="text-danger">*</span></label>
                                <select class="form-select" id="maintainable_type" name="maintainable_type" required>
                                    <option value="" disabled selected>Pilih kategori</option>
                                    <option value="item" <?php echo e(old('maintainable_type') == 'item' ? 'selected' : ''); ?>>Barang Inventaris (Meja, Kursi, Laptop, dll)</option>
                                    <option value="facility" <?php echo e(old('maintainable_type') == 'facility' ? 'selected' : ''); ?>>Fasilitas Ruangan (Lantai, Jendela, Atap, dll)</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="maintainable_id">Pilih Objek / Barang <span class="text-danger">*</span></label>
                                <select class="form-select" id="maintainable_id" name="maintainable_id" required>
                                    <option value="" selected disabled>Pilih kategori terlebih dahulu</option>
                                    <optgroup label="Barang Inventaris" id="group-item" class="d-none">
                                        <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($item->id); ?>" data-type="item"><?php echo e($item->name); ?> (<?php echo e($item->location?->name); ?>)</option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </optgroup>
                                    <optgroup label="Fasilitas" id="group-facility" class="d-none">
                                        <?php $__currentLoopData = $facilities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $facility): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($facility->id); ?>" data-type="facility"><?php echo e($facility->name); ?> (<?php echo e($facility->location?->name); ?>)</option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </optgroup>
                                    <option value="other">-- Lainnya (Isi Sendiri) --</option>
                                </select>
                            </div>
                            <div class="col-md-6 d-none" id="custom-object-wrapper">
                                <label class="form-label" for="object_name">Nama Objek Lainnya <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="object_name" name="object_name" placeholder="Contoh: AC Ruang Kelas A" value="<?php echo e(old('object_name')); ?>">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="location_id">Lokasi <span class="text-danger">*</span></label>
                                <select class="form-select" id="location_id" name="location_id">
                                    <option value="" selected>Pilih lokasi</option>
                                    <?php $__currentLoopData = $locations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $location): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($location->id); ?>" <?php echo e(old('location_id') == $location->id ? 'selected' : ''); ?>><?php echo e($location->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <option value="other">-- Lainnya (Isi Sendiri) --</option>
                                </select>
                            </div>
                            <div class="col-md-6 d-none" id="custom-location-wrapper">
                                <label class="form-label" for="custom_location">Nama Lokasi Lainnya <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="custom_location" name="custom_location" placeholder="Masukkan nama lokasi" value="<?php echo e(old('custom_location')); ?>">
                            </div>
                            <div class="col-12">
                                <label class="form-label" for="description">Detail Kerusakan <span class="text-danger">*</span></label>
                                <textarea id="description" name="description" class="form-control" placeholder="Jelaskan secara detail kerusakan yang terjadi..." required rows="4"><?php echo e(old('description')); ?></textarea>
                            </div>
                            <div class="col-12">
                                <label class="form-label" for="photo">Foto Kerusakan (Opsional)</label>
                                <input type="file" class="form-control" id="photo" name="photo" accept="image/*">
                                <div class="form-text">Format: JPG, PNG, JPEG. Max: 5MB</div>
                            </div>
                            <div class="col-12 mt-6">
                                <button type="submit" class="btn btn-success w-100 py-3 waves-effect waves-light">
                                    <i class="ti tabler-send me-1"></i> Kirim Laporan Tiket
                                </button>
                                <div class="text-center mt-4">
                                    <a href="<?php echo e(route('public.home')); ?>" class="text-muted small"><i class="ti tabler-arrow-left me-1"></i> Kembali ke Beranda</a>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->startPush('scripts'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const typeSelect = document.getElementById('maintainable_type');
        const objectSelect = document.getElementById('maintainable_id');
        const customObjectWrapper = document.getElementById('custom-object-wrapper');
        const customObjectInput = document.getElementById('object_name');
        
        const groupItem = document.getElementById('group-item');
        const groupFacility = document.getElementById('group-facility');

        // Handle Type Change
        typeSelect.addEventListener('change', function() {
            const type = this.value;
            objectSelect.value = "";
            customObjectWrapper.classList.add('d-none');
            customObjectInput.removeAttribute('required');
            
            if (type === 'item') {
                groupItem.classList.remove('d-none');
                groupFacility.classList.add('d-none');
            } else {
                groupItem.classList.add('d-none');
                groupFacility.classList.remove('d-none');
            }
        });

        // Handle Object Change
        objectSelect.addEventListener('change', function() {
            if (this.value === 'other') {
                customObjectWrapper.classList.remove('d-none');
                customObjectInput.setAttribute('required', 'required');
            } else {
                customObjectWrapper.classList.add('d-none');
                customObjectInput.removeAttribute('required');
            }
        });

        // Handle Location Change
        const locationSelect = document.getElementById('location_id');
        const customLocationWrapper = document.getElementById('custom-location-wrapper');
        const customLocationInput = document.getElementById('custom_location');

        locationSelect.addEventListener('change', function() {
            if (this.value === 'other') {
                customLocationWrapper.classList.remove('d-none');
                customLocationInput.setAttribute('required', 'required');
            } else {
                customLocationWrapper.classList.add('d-none');
                customLocationInput.removeAttribute('required');
            }
        });
    });
</script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.front', ['title' => 'Lapor Kerusakan'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH G:\Project\inventaris-pondok\resources\views/public/tickets/create.blade.php ENDPATH**/ ?>