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

    <div class="card-body">
        <form id="editForm">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>

            <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($dynamicAttribute->branch_id == $branch->id ? 'selected' : ''); ?>>
                            <?php echo e($branch->name); ?>

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

            <div class="mb-3">
                <label class="form-label">Entity Type <span class="text-danger">*</span></label>
                <input type="text" name="entity_type"
                       value="<?php echo e($dynamicAttribute->entity_type); ?>"
                       class="form-control" maxlength="50" required>
            </div>

            <div class="mb-3">
                <label class="form-label">Attribute Name <span class="text-danger">*</span></label>
                <input type="text" name="name"
                       value="<?php echo e($dynamicAttribute->name); ?>"
                       class="form-control" maxlength="150" required>
            </div>

            <div class="mb-3">
                <label class="form-label">Data Type <span class="text-danger">*</span></label>
                <select name="data_type" class="form-control" required>
                    <?php $__currentLoopData = ['text','number','date','boolean','dropdown']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($type); ?>"
                            <?php echo e($dynamicAttribute->data_type === $type ? 'selected' : ''); ?>>
                            <?php echo e(ucfirst($type)); ?>

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

            <div class="mb-3">
                <label class="form-label">Validation Rule</label>
                <input type="text" name="validation_rule"
                       value="<?php echo e($dynamicAttribute->validation_rule); ?>"
                       class="form-control">
            </div>

            <div class="form-check mb-2">
                <input type="checkbox" name="mandatory" class="form-check-input"
                    <?php echo e($dynamicAttribute->mandatory ? 'checked' : ''); ?>>
                <label class="form-check-label">Mandatory</label>
            </div>

            <div class="form-check mb-3">
                <input type="checkbox" name="status" class="form-check-input"
                    <?php echo e($dynamicAttribute->status ? 'checked' : ''); ?>>
                <label class="form-check-label">Active</label>
            </div>

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

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

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

    $.ajax({
        url: "<?php echo e(route('core.dynamic-attributes.update', $dynamicAttribute->id)); ?>",
        type: "POST",
        data: $(this).serialize(),
        success: function (res) {
            Swal.fire('Success', res.message, 'success')
                .then(() => window.location.href = "<?php echo e(route('core.dynamic-attributes.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/dynamic_attributes/edit.blade.php ENDPATH**/ ?>