<?php $__env->startSection('content'); ?>
    <!-- HEADER -->
    <div class="d-flex justify-content-between align-items-center mb-3">
        <div>
            <h2 class="mb-0">Tambah Karyawan</h2>
            <small class="text-muted">
                Input data karyawan baru
            </small>
        </div>

        <a href="<?php echo e(route('karyawan.index')); ?>" class="btn btn-outline-secondary rounded-3 px-4">
            <i class="bi bi-arrow-left me-1"></i> Kembali
        </a>
    </div>

    <!-- CARD -->
    <div class="card border-0 shadow-sm rounded-4">

        <!-- GOLD LINE -->
        <div style="height:4px; background:#d6a100;"></div>

        <div class="card-body p-4">

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

                <?php echo csrf_field(); ?>

                <div class="row align-items-start g-4">

                    <!-- FOTO -->
                    <div class="col-lg-3 text-center">

                        <img id="img-preview"
                            src="https://ui-avatars.com/api/?name=Karyawan&background=f1f3f5&color=6c757d&size=300"
                            class="rounded-4 border shadow-sm mb-3" style="width:170px; height:210px; object-fit:cover;">

                        <div>
                            <label for="foto" class="btn btn-light border rounded-3 px-3 w-100">
                                <i class="bi bi-camera me-1"></i>
                                Upload Foto
                            </label>

                            <input type="file" id="foto" name="foto"
                                class="d-none <?php $__errorArgs = ['foto'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" accept="image/*"
                                onchange="previewImage()">

                            <?php $__errorArgs = ['foto'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <div class="text-danger small mt-2">
                                    <?php echo e($message); ?>

                                </div>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                    </div>

                    <!-- FORM -->
                    <div class="col-lg-9">

                        <div class="row g-3">

                            <div class="col-md-6">
                                <label class="form-label small fw-semibold">
                                    NRP
                                </label>

                                <input type="text" name="nrp" value="<?php echo e(old('nrp')); ?>"
                                    class="form-control rounded-3 <?php $__errorArgs = ['nrp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                    placeholder="Masukkan NRP">
                                <span id="messageNRP" class="text-danger small mt-1 d-block"></span>
                                <?php $__errorArgs = ['nrp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback">
                                        <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label small fw-semibold">
                                    Nama
                                </label>

                                <input type="text" name="nama" value="<?php echo e(old('nama')); ?>"
                                    class="form-control rounded-3 <?php $__errorArgs = ['nama'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                    placeholder="Masukkan Nama">
                                <span id="messageNama" class="text-danger small mt-1 d-block"></span>
                                <?php $__errorArgs = ['nama'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback">
                                        <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label small fw-semibold">
                                    Jabatan
                                </label>

                                <input type="text" name="jabatan" value="<?php echo e(old('jabatan')); ?>"
                                    class="form-control rounded-3 <?php $__errorArgs = ['jabatan'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                    placeholder="Contoh: Group Leader">
                                <span id="messageJabatan" class="text-danger small mt-1 d-block"></span>
                                <?php $__errorArgs = ['jabatan'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback">
                                        <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label small fw-semibold">
                                    Atasan
                                </label>

                                <select name="atasan_id"
                                    class="form-select rounded-3 <?php $__errorArgs = ['atasan_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">

                                    <option value="">
                                        Tidak Ada
                                    </option>

                                    <?php $__currentLoopData = $atasans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($item->id); ?>"
                                            <?php echo e(old('atasan_id') == $item->id ? 'selected' : ''); ?>>
                                            <?php echo e($item->nama); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                </select>
                                <?php $__errorArgs = ['atasan_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback">
                                        <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label small fw-semibold">
                                    Departemen
                                </label>

                                <select name="departemen"
                                    class="form-select rounded-3 <?php $__errorArgs = ['departemen'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>">

                                    <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>
                                <span id="messageDepartemen" class="text-danger small mt-1 d-block"></span>
                                <?php $__errorArgs = ['departemen'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback">
                                        <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label small fw-semibold">
                                    Plant
                                </label>

                                <input type="text" name="plant" value="<?php echo e(old('plant')); ?>"
                                    class="form-control rounded-3 <?php $__errorArgs = ['plant'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                    placeholder="Masukkan Plant">
                                <span id="messagePlant" class="text-danger small mt-1 d-block"></span>
                                <?php $__errorArgs = ['plant'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback">
                                        <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>

                        </div>

                        <!-- BUTTON -->
                        <div class="mt-4 d-flex justify-content-end">
                            <button type="submit" class="btn btn-warning rounded-3 px-4 fw-semibold shadow-sm">
                                <i class="bi bi-check-circle me-1"></i>
                                Simpan
                            </button>
                        </div>

                    </div>

                </div>

            </form>

        </div>
    </div>

    <script>
        function previewImage() {
            const file = document.getElementById('foto').files[0];
            const preview = document.getElementById('img-preview');

            if (file) {
                preview.src = URL.createObjectURL(file);
            }
        }

        document.getElementById('formKaryawan').addEventListener('submit', function(e) {

            let valid = true;

            // ambil input
            const nrp = document.querySelector('[name="nrp"]');
            const nama = document.querySelector('[name="nama"]');
            const jabatan = document.querySelector('[name="jabatan"]');
            const departemen = document.querySelector('[name="departemen"]');
            const plant = document.querySelector('[name="plant"]');

            // ambil message
            const messageNRP = document.getElementById('messageNRP');
            const messageNama = document.getElementById('messageNama');
            const messageJabatan = document.getElementById('messageJabatan');
            const messageDepartemen = document.getElementById('messageDepartemen');
            const messagePlant = document.getElementById('messagePlant');

            // reset message
            messageNRP.textContent = '';
            messageNama.textContent = '';
            messageJabatan.textContent = '';
            messageDepartemen.textContent = '';
            messagePlant.textContent = '';

            // VALIDASI
            if (!nrp.value.trim()) {
                messageNRP.textContent = 'NRP wajib diisi';
                nrp.classList.add('is-invalid');
                valid = false;
            } else {
                nrp.classList.remove('is-invalid');
            }

            if (!nama.value.trim()) {
                messageNama.textContent = 'Nama wajib diisi';
                nama.classList.add('is-invalid');
                valid = false;
            } else {
                nama.classList.remove('is-invalid');
            }

            if (!jabatan.value.trim()) {
                messageJabatan.textContent = 'Jabatan wajib diisi';
                jabatan.classList.add('is-invalid');
                valid = false;
            } else {
                jabatan.classList.remove('is-invalid');
            }

            if (!departemen.value) {
                messageDepartemen.textContent = 'Departemen wajib dipilih';
                departemen.classList.add('is-invalid');
                valid = false;
            } else {
                departemen.classList.remove('is-invalid');
            }

            if (!plant.value.trim()) {
                messagePlant.textContent = 'Plant wajib diisi';
                plant.classList.add('is-invalid');
                valid = false;
            } else {
                plant.classList.remove('is-invalid');
            }

            if (!valid) {
                e.preventDefault();
            }
        });
    </script>
<?php $__env->stopSection(); ?>

<?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/menu/karyawan/create.blade.php ENDPATH**/ ?>