<?php $__env->startSection('content'); ?>
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>Buat Laporan Baru</h2>
        <a href="<?php echo e(route('laporan.index')); ?>" class="btn btn-secondary"><i class="fas fa-arrow-left me-1"></i> Kembali</a>
    </div>

    <form method="POST" action="<?php echo e(route('laporan.store')); ?>" enctype="multipart/form-data" id="laporanForm">
        <?php echo csrf_field(); ?>

        <!-- Bagian 1: Data Utama -->
        <div class="card shadow-sm mb-4 border-0">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>Informasi Umum</h5>
            </div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label">Tanggal</label>
                        <input type="date" class="form-control" name="tanggal"
                            value="<?php echo e(old('tanggal', date('Y-m-d'))); ?>" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Nama GL</label>
                        <input type="text" class="form-control" name="nama_gl"
                            value="<?php echo e(old('nama_gl', Auth::user()->name)); ?>" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Departemen</label>
                        <select class="form-select" name="departemen" required>
                            <option value="">-- Pilih Departemen --</option>
                            <?php $__currentLoopData = ['PRODUKSI', 'HCGS', 'SHE', 'ENG', 'LOG', 'SLD']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dept): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($dept); ?>" <?php echo e(old('departemen') == $dept ? 'selected' : ''); ?>>
                                    <?php echo e($dept); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Plant</label>
                        <input type="text" class="form-control" name="plant" value="<?php echo e(old('plant')); ?>" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Nama Manpower</label>
                        <input type="text" class="form-control" name="nama_manpower" value="<?php echo e(old('nama_manpower')); ?>"
                            required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Jabatan</label>
                        <input type="text" class="form-control" name="jabatan" value="<?php echo e(old('jabatan')); ?>" required>
                    </div>
                </div>
            </div>
        </div>

        <!-- Bagian 2: Penilaian -->
        <div class="card shadow-sm mb-4 border-0">
            <div class="card-header bg-success text-white">
                <h5 class="mb-0"><i class="fas fa-check-square me-2"></i>Penilaian</h5>
            </div>
            <div class="card-body p-0">
                <table class="table table-bordered mb-0">
                    <thead class="table-light">
                        <tr>
                            <th width="30%">Kategori (Target)</th>
                            <th width="20%">Status</th>
                            <th width="50%">Keterangan (Wajib jika tidak tercapai)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $kategoris = [
                                'SHE Culture' => 'Target 100%',
                                'ATR' => 'Target 99%',
                                'Incident' => 'Target Zero',
                                'Manpower Behavior' => 'Target Zero',
                            ];
                        ?>
                        <?php $__currentLoopData = $kategoris; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kategori => $target): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="align-middle">
                                    <strong><?php echo e($kategori); ?></strong><br>
                                    <small class="text-muted"><?php echo e($target); ?></small>
                                </td>
                                <td class="align-middle text-center">
                                    <div class="btn-group" role="group" aria-label="Status <?php echo e($kategori); ?>">
                                        <input type="radio" class="btn-check"
                                            name="penilaian[<?php echo e($kategori); ?>][status]"
                                            id="status_<?php echo e(Str::slug($kategori)); ?>_1" value="1"
                                            <?php echo e(old("penilaian.{$kategori}.status") == '1' ? 'checked' : ''); ?> required>
                                        <label class="btn btn-outline-success"
                                            for="status_<?php echo e(Str::slug($kategori)); ?>_1">Tercapai</label>

                                        <input type="radio" class="btn-check"
                                            name="penilaian[<?php echo e($kategori); ?>][status]"
                                            id="status_<?php echo e(Str::slug($kategori)); ?>_0" value="0"
                                            <?php echo e(old("penilaian.{$kategori}.status") === '0' ? 'checked' : ''); ?> required>
                                        <label class="btn btn-outline-danger"
                                            for="status_<?php echo e(Str::slug($kategori)); ?>_0">Tidak</label>
                                    </div>
                                </td>
                                <td>
                                    <textarea class="form-control" name="penilaian[<?php echo e($kategori); ?>][keterangan]" rows="2"
                                        placeholder="Masukkan keterangan..."><?php echo e(old("penilaian.{$kategori}.keterangan")); ?></textarea>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- Bagian 3: Tambahan -->
        <div class="card shadow-sm mb-4 border-0">
            <div class="card-header bg-info text-white">
                <h5 class="mb-0"><i class="fas fa-file-alt me-2"></i>Informasi Tambahan</h5>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <label class="form-label">Note</label>
                    <textarea class="form-control" name="note" rows="3"><?php echo e(old('note')); ?></textarea>
                </div>
                <div class="mb-3">
                    <label class="form-label">Feedback</label>
                    <textarea class="form-control" name="feedback" rows="3"><?php echo e(old('feedback')); ?></textarea>
                </div>
                <div class="mb-3">
                    <label class="form-label">Upload Foto Kegiatan</label>
                    <input class="form-control" type="file" name="foto" accept="image/*">
                    <div class="form-text">Maksimal ukuran file: 2MB. Format: JPG, PNG, JPEG.</div>
                </div>
            </div>
        </div>

        <div class="text-end mb-5">
            <button type="submit" class="btn btn-primary btn-lg px-5 shadow"><i class="fas fa-save me-2"></i>Simpan
                Laporan</button>
        </div>
    </form>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        // Simple frontend validation for required 'keterangan' if status is 'Tidak tercapai'
        document.getElementById('laporanForm').addEventListener('submit', function(e) {
            const radios = document.querySelectorAll('input[type="radio"][value="0"]:checked');
            let isValid = true;

            radios.forEach(function(radio) {
                const row = radio.closest('tr');
                const textarea = row.querySelector('textarea');
                if (textarea.value.trim() === '') {
                    isValid = false;
                    textarea.classList.add('is-invalid');
                } else {
                    textarea.classList.remove('is-invalid');
                }
            });

            if (!isValid) {
                e.preventDefault();
                alert('Harap isi keterangan untuk penilaian yang "Tidak Tercapai"');
            }
        });

        // Remove is-invalid class when user types
        document.querySelectorAll('textarea').forEach(function(textarea) {
            textarea.addEventListener('input', function() {
                this.classList.remove('is-invalid');
            });
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts/app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\gl-asuh\resources\views/laporan/create.blade.php ENDPATH**/ ?>