<style>
  .radio-inline label {
    display: inline-block; /* Ensure the labels are displayed inline */
    margin-right: 10px; /* Adjust spacing between radio buttons and labels */
}

</style>
<div class="row">
                        <div class="col-sm-11">
                            <div class="page-title-box">
                                    <h2 class="page-title">Create Subadmin</h2>
                            </div><!--end page-title-box-->
                        </div><!--end col-->
                        <div class="col-sm-1">
        <div class="page-title-box">
            <h2 class="page-title"><a href="subadmin_list"><button  class='btn btn-danger' type="button">Back</button></a></h2>
        </div><!--end page-title-box-->
    </div><!--end col-->
                    </div>
                    
                    <div class="row" >
                        <div class="col-sm-12">
                            <div class="card">
                                <div class="card-body">
                                    <?php echo $this->Form->create('User', array('type'=>'file')); ?>
                                   
                                    <div class="form-group row">
                                        
                                        <div class="col-sm-8">
                                            <?php 
                                                echo $this->Form->input('name', array('div'=>array('class'=>'form-group'), 'label'=>array('class'=>'form-label'), 'class'=>'form-control','required'=>true));
                                                // echo $this->Form->input('mobile', array('div'=>array('class'=>'form-group'), 'label'=>'Mobile', 'class'=>'form-control','required'=>'required','type'=>'number'));
                                          echo $this->Form->input('mobile', array(
    'div' => array('class' => 'form-group'),
    'label' => 'Mobile',
    'class' => 'form-control',
    'required' => 'required',
    'type' => 'number',
    'min' => '1000000000', // Minimum value for a 10-digit number
    'max' => '9999999999', // Maximum value for a 10-digit number
    'oninput' => 'this.value = this.value.slice(0, 10);' // Ensure input is no more than 10 digits
));
echo $this->Form->input('username', array('div'=>array('class'=>'form-group'), 'label'=>'User Name', 'class'=>'form-control','required'=>'required'));
                                                echo $this->Form->input('password', array('div'=>array('class'=>'form-group'), 'label'=>'Password', 'class'=>'form-control','required'=>'required','type'=>'password'));

$options=[''=>'Select location'];
foreach($locations as $location){
$options[$location['Location']['id']] = $location['Location']['name'];
}
echo $this->Form->input('location', array('div'=>array('class'=>'form-group'), 'label'=>'Select Location','multiple' => 'multiple', 'class'=>'form-control select2', 'between'=>'<span class="desc"></span><div class="controls">', 'after'=>'</div>','options'=>$options,'id'=>'location','required'=>true));

$roleoptions = ['subadmin' => 'Sub-admin', 'kitchen' => 'Kitchen'];
echo $this->Form->input('role', array(
    'div' => array('class' => 'form-group'),
    'label' => 'Select Role',
    'class' => 'form-control',
    'between' => '<span class="desc"></span><div class="controls">',
    'after' => '</div>',
    'options' => $roleoptions,
    'id' => 'role',
    'required' => true
));

                                                echo "<h5>Select Modules</h5>";
                                                foreach ($modules as $moduleKey => $moduleLabel) {
                                                    echo $this->Form->input($moduleKey, array('label' => $moduleLabel, 'type' => 'checkbox'));
                                                }

?>

                                        </div>
                                    </div>
                                    <a href="cashier_list"><button  class='btn btn-danger' type="button">Cancel</button></a>
                                    <?php echo $this->Form->button('Save', array('class'=>'btn btn-success', 'type'=>'submit', 'id' => 'submitBtn')); ?>
                                </div>
                            </div>
                        </div> 
                    </div>
<style>
    .hidden{
        display:none;
    }
    
</style>
<script>
    $(document).ready(function() {
        

$('#submitBtn').click(function() {
    
        const checkboxes = document.querySelectorAll('input[type="checkbox"]');
        let atLeastOneChecked = false;
        checkboxes.forEach(function(checkbox) {
            if (checkbox.checked) {
                atLeastOneChecked = true;
            }
        });
        if (!atLeastOneChecked) {
            event.preventDefault(); // Prevent form submission if no checkbox is checked
            Swal.fire({
                icon: 'warning',
                title: 'Please select at least one module.',
                confirmButtonText: 'OK'
            });
        }
    });



    });
    
    jQuery(document).ready(function($) {
                        if ($.fn.select2) {
                            $('.select2').select2({
                                placeholder: "Select locations",
                                allowClear: true,
                                width: '100%'
                            });
                        } else {
                            console.error("Select2 library not loaded!");
                        }
                    });
    
</script>                   