<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-header">
        <h5>Add Grade</h5>
    </div>

    <div class="card-body">
        <form id="createForm">
            <?php echo csrf_field(); ?>

            <div class="mb-3">
                <label class="form-label">Branch <span class="text-danger">*</span></label>
                <select name="branch_id" class="form-control">
                    <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($branch->id); ?>">
                            <?php echo e($branch->name); ?>

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

            <div class="mb-3">
                <label class="form-label">Grade Code <span class="text-danger">*</span></label>
                <input type="text" name="name" class="form-control" maxlength="50" required>
            </div>

            <div class="mb-3">
                <label class="form-label">Min Salary</label>
                <input type="number" name="min_salary" step="0.01" class="form-control">
            </div>

            <div class="mb-3">
                <label class="form-label">Max Salary</label>
                <input type="number" name="max_salary" step="0.01" class="form-control">
            </div>

            <div class="mb-3">
                <label class="form-label">Currency</label>
                <select name="currency_id" class="form-control">
                    <option value="">-- Select --</option>
                    <?php $__currentLoopData = $currencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $currency): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($currency->id); ?>">
                            <?php echo e($currency->iso_code); ?>

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

            <div class="form-check mb-3">
                <input type="checkbox" name="status" class="form-check-input" checked>
                <label class="form-check-label">Active</label>
            </div>

            <button type="submit" class="btn btn-primary">Save</button>
            <a href="<?php echo e(route('core.grades.index')); ?>" class="btn btn-secondary">Back</a>
        </form>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
$('#createForm').on('submit', function (e) {
    e.preventDefault();

    let btn = $(this).find('button[type=submit]');
    btn.prop('disabled', true);

    $.ajax({
        url: "<?php echo e(route('core.grades.store')); ?>",
        type: "POST",
        data: $(this).serialize(),
        success: function (res) {
            Swal.fire('Success', res.message, 'success')
                .then(() => window.location.href = "<?php echo e(route('core.grades.index')); ?>");
        },
        error: function (xhr) {
            btn.prop('disabled', false);
            if (xhr.status === 422) {
                let errors = xhr.responseJSON.errors;
                let errorList = '<ul style="text-align: left;">';
                $.each(errors, function(field, messages) {
                    $.each(messages, function(index, message) {
                        errorList += '<li>' + message + '</li>';
                    });
                });
                errorList += '</ul>';
                Swal.fire({
                    title: 'Validation Error',
                    html: errorList,
                    icon: 'error'
                });
            } else {
                Swal.fire('Error', 'An error occurred. Please try again.', 'error');
            }
        }
    });
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/codeproh/va.laraoffice.com/app/Modules/HR/Core/Providers/../Views/grades/create.blade.php ENDPATH**/ ?>