<?php if (isset($component)) { $__componentOriginal1f9e5f64f242295036c059d9dc1c375c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal1f9e5f64f242295036c059d9dc1c375c = $attributes; } ?>
<?php $component = App\View\Components\Layout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\Layout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
    <div class="mb-4">
        <h2 class="text-xl font-semibold text-white">Add Unit</h2>
    </div>
    <div class="bg-slate-800 rounded-md shadow-lg border-t-4 border-t-indigo-500 max-w-full">
        <div class="border-b border-slate-700 px-6 py-3.5">
            <h3 class="text-base font-medium text-slate-100">Unit Details Form</h3>
        </div>
        <form action="<?php echo e(route('master_unit.update', $unitData->unit_code)); ?>" method="POST" id="unitForm">
            <?php echo method_field('PUT'); ?>
            <?php echo csrf_field(); ?>
            <div class="p-6 space-y-5">
                <div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
                    <div>
                        <label for="unit_code" class="block text-sm font-medium text-slate-300 mb-1">
                            Unit Code <span class="text-red-400">*</span>
                        </label>
                        <input type="text" name="unit_code" id="unit_code" value="<?php echo e($unitData->unit_code); ?>"
                            class="block w-full rounded-sm border border-slate-700 bg-slate-900/50 py-2.5 px-3 text-slate-400 shadow-sm cursor-not-allowed focus:ring-0 sm:text-sm sm:leading-6" readonly>
                        <?php $__errorArgs = ['unit_code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-red-400 text-xs italic mt-1 block"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div>
                        <label for="unit_name" class="block text-sm font-medium text-slate-300 mb-1">
                            Unit Name <span class="text-red-400">*</span>
                        </label>
                        <input type="text" name="unit_name" id="unit_name" value="<?php echo e($unitData->unit_name); ?>"
                            class="block w-full rounded-sm border border-slate-600 bg-slate-900 py-2 px-3 text-sm text-white placeholder:text-slate-500 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 transition-colors">
                        <?php $__errorArgs = ['unit_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-red-400 text-xs italic mt-1 block"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                </div>
                <div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
                    <div class="w-full">
                        <label for="project_code" class="block text-sm font-medium text-slate-300 mb-1">
                            Project <span class="text-red-400">*</span>
                        </label>
                        <select id="project_code" name="project_code"
                            class="block w-full rounded-sm border border-slate-600 bg-slate-900 py-2 pl-3 pr-10 text-sm text-white focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 cursor-pointer [&>option]:bg-slate-800">
                            <option value="" disabled selected> --- </option>
                            <?php $__empty_1 = true; $__currentLoopData = $projects; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $project): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <?php
                                    $selectedProjectCode    = $project->project_code;  
                                ?>
                                <option value="<?php echo e($selectedProjectCode); ?>" <?php echo e(($selectedProjectCode == $unitData->project_code) ? 'selected' : ''); ?>><?php echo e($selectedProjectCode . ' - ' .$project->project_name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <option value="">Project not found</option>
                            <?php endif; ?>
                        </select>
                        <?php $__errorArgs = ['project_code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-red-400 text-xs italic mt-1 block"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="w-full">
                        <label for="status" class="block text-sm font-medium text-slate-300 mb-1">
                            Status <span class="text-red-400">*</span>
                        </label>
                        <select id="status" name="status"
                            class="block w-full rounded-sm border border-slate-600 bg-slate-900 py-2 pl-3 pr-10 text-sm text-white focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 cursor-pointer [&>option]:bg-slate-800">
                            <option value=""> --- </option>
                            <option value="1" <?php echo e(($unitData->status == 1) ? 'selected' : ''); ?>>Active</option>
                            <option value="0" <?php echo e(($unitData->status == 0) ? 'selected' : ''); ?>>Inactive</option>
                        </select>
                        <?php $__errorArgs = ['status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-red-400 text-xs italic mt-1 block"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                </div>
                <div>
                    <label for="description" class="block text-sm font-medium text-slate-300 mb-1">
                        Description
                    </label>
                    <textarea name="description" id="description" rows="3" placeholder="Unit desriptions ..."
                        class="block w-full rounded-sm border border-slate-600 bg-slate-900 py-2 px-3 text-sm text-white placeholder:text-slate-500 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 transition-colors"><?php echo e($unitData->description); ?></textarea>
                </div>
            </div>
            <div class="bg-slate-900/50 border-t border-slate-700 px-6 py-4 flex items-center justify-end gap-3 rounded-b-md">
                <a href="/unit/master_unit" class="inline-flex items-center gap-2 text-sm font-medium bg-slate-700 text-white hover:bg-slate-600 px-4 py-2 rounded-sm transition-colors border border-slate-600">
                    <?php if (isset($component)) { $__componentOriginal643fe1b47aec0b76658e1a0200b34b2c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c = $attributes; } ?>
<?php $component = BladeUI\Icons\Components\Svg::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('iconpark-back'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\BladeUI\Icons\Components\Svg::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['class' => 'w-4 h-4']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c)): ?>
<?php $attributes = $__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c; ?>
<?php unset($__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal643fe1b47aec0b76658e1a0200b34b2c)): ?>
<?php $component = $__componentOriginal643fe1b47aec0b76658e1a0200b34b2c; ?>
<?php unset($__componentOriginal643fe1b47aec0b76658e1a0200b34b2c); ?>
<?php endif; ?> Batal
                </a>
                <button type="submit" class="inline-flex items-center gap-2 text-sm font-medium bg-indigo-600 text-white hover:bg-indigo-500 px-4 py-2 rounded-sm transition-colors cursor-pointer shadow-sm">
                    <?php if (isset($component)) { $__componentOriginal643fe1b47aec0b76658e1a0200b34b2c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c = $attributes; } ?>
<?php $component = BladeUI\Icons\Components\Svg::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('iconpark-save'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\BladeUI\Icons\Components\Svg::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['class' => 'w-4 h-4']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c)): ?>
<?php $attributes = $__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c; ?>
<?php unset($__attributesOriginal643fe1b47aec0b76658e1a0200b34b2c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal643fe1b47aec0b76658e1a0200b34b2c)): ?>
<?php $component = $__componentOriginal643fe1b47aec0b76658e1a0200b34b2c; ?>
<?php unset($__componentOriginal643fe1b47aec0b76658e1a0200b34b2c); ?>
<?php endif; ?> Simpan
                </button>
            </div>
        </form>
    </div>
    <script>
        function preventSpecialChar(evt) {
            if (evt.which) {
                var charCode = evt.which;
            } else if (document.all && event.keyCode) {
                var charCode = event.keyCode;
            } else {
                return true;
            }

            return (
                (charCode >= 48 && charCode <= 57) || // 0-9
                (charCode >= 65 && charCode <= 90) || // A-Z
                (charCode >= 97 && charCode <= 122) || // a-z
                charCode == 45 || // -
                charCode == 46 || // .
                charCode == 8    // Backspace
            );
        }
        
        const form = document.getElementById('unitForm');
	    form.addEventListener('submit', (event) => {
            event.preventDefault();

            let unit_code        = document.getElementById('unit_code');
            let unit_name        = document.getElementById('unit_name');
            let project_code     = document.getElementById('project_code');
            let status           = document.getElementById('status');

            // Konfigurasi warna default untuk SweetAlert agar Dark Mode
            const swalDarkConfig = {
                background: '#1e293b', // bg-slate-800
                color: '#f8fafc'       // text-slate-50
            };

            if(unit_code.value == ''){
                unit_code.blur();
                Swal.fire({
                    // title: "Good job!",
                    text: "Unit code is required",
                    icon: "warning",
                    ...swalDarkConfig
                }).then(() =>{
                    unit_code.focus()
                })

                return false;
            }

            if(unit_name.value == ''){
                unit_name.blur();
                Swal.fire({
                    // title: "Good job!",
                    text: "Unit name is required",
                    icon: "warning",
                    ...swalDarkConfig
                }).then(() =>{
                    unit_name.focus()
                })

                return false;
            }

            if(project_code.value == ''){
                Swal.fire({
                    // title: "Good job!",
                    text: "Project is required",
                    icon: "warning",
                    ...swalDarkConfig
                });
                return false;
            }

            if(status.value == ''){
                Swal.fire({
                    // title: "Good job!",
                    text: "Unit status is required",
                    icon: "warning",
                    ...swalDarkConfig
                });
                return false;
            }

            Swal.fire({
                title: "Data updated",
                // text: "You clicked the button!",
                icon: "success",
                ...swalDarkConfig
            });

            form.submit();
        })
    </script>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal1f9e5f64f242295036c059d9dc1c375c)): ?>
<?php $attributes = $__attributesOriginal1f9e5f64f242295036c059d9dc1c375c; ?>
<?php unset($__attributesOriginal1f9e5f64f242295036c059d9dc1c375c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal1f9e5f64f242295036c059d9dc1c375c)): ?>
<?php $component = $__componentOriginal1f9e5f64f242295036c059d9dc1c375c; ?>
<?php unset($__componentOriginal1f9e5f64f242295036c059d9dc1c375c); ?>
<?php endif; ?><?php /**PATH C:\Users\Hype\Herd\symmapan\resources\views/unit/unit_detail.blade.php ENDPATH**/ ?>