<div class="content-wrapper">
    <div class="container-xxl flex-grow-1 container-p-y">
        <div class="row">
            <div class="col">
                <div class="card shadow">
                    <div class="card-header text-uppercase custom-header bg-primary text-bg-info fw-bold">
                        <i class="menu-icon ti ti-users-plus"></i> Assign Division
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <form action="/updateuserdivisiondata" method="POST">
                                <?php echo csrf_field(); ?>
                                <?php if($errors->any()): ?>
                                    <div class="row">
                                        <?php echo implode(
                                            '',
                                            $errors->all('<div class="mt-3 alert alert-danger col-sm-12 col-md-12" role="alert">:message</div>'),
                                        ); ?>

                                    </div>
                                <?php endif; ?>

                                <?php if(session('success')): ?>
                                    <div class="mt-3 alert alert-success success-alert">
                                        <?php echo e(session('success')); ?>

                                    </div>
                                <?php endif; ?>

                                <?php if(session('error')): ?>
                                    <div class="mt-3 alert alert-danger danger-alert">
                                        <?php echo e(session('error')); ?>

                                    </div>
                                <?php endif; ?>

                                <div class="row mt-3">
                                    <div class="col-md-4 col-sm-12 mt-3">
                                        <div class="form-group">
                                            <label class="fw-bold">Name</label>
                                            <p class="ml-3"><?php echo e($users->name); ?></p>
                                        </div>
                                    </div>
                                    <div class="col-md-6 d-flex justify-content-end col-sm-12 mt-3">
                                        <div class="form-group">
                                            <label class="fw-bold">Email</label>
                                            <p class="ml-3"><?php echo e($users->email); ?></p>
                                        </div>
                                    </div>
                                    <input type="hidden" name="userId" id="userId" class="form-control"
                                        value="<?php echo e($users->id); ?>">
                                    <input type="hidden" name="userVillage" id="userVillage" class="form-control"
                                        value="<?php echo e($users->village); ?>">

                                    <div class="row">
                                        <label for="assignDivisionId" class="form-label fw-bold">Select Division &
                                            Village</label>
                                        <?php $__currentLoopData = $getDivision; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $division): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="col-sm-12 col-md-3">
                                                <div class="form-check">
                                                    <input class="form-check-input division-checkbox" type="checkbox"
                                                        name="permissionsDivision[]" value="<?php echo e($division->id); ?>"
                                                        id="division-<?php echo e($division->id); ?>"
                                                        <?php if($users->division == '' || $users->division == null): ?> <?php elseif(in_array($division->id, json_decode($users->division, true))): ?> checked <?php endif; ?>>
                                                    <label class="form-check-label" for="division-<?php echo e($division->id); ?>">
                                                        <?php echo e($division->divisionName); ?>

                                                    </label>
                                                </div>
                                                <?php $__currentLoopData = $getVillage; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $village): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($village->divisionId == $division->id): ?>
                                                        <div class="form-check ms-4">
                                                            <input
                                                                class="form-check-input village-checkbox division-<?php echo e($division->id); ?>-village"
                                                                type="checkbox" name="permissionsVillage[]"
                                                                value="<?php echo e($village->id); ?>"
                                                                id="village-<?php echo e($village->id); ?>" <?php if($users->village == '' || $users->village == null || $users->village == "null"): ?> <?php elseif(in_array($village->id, json_decode($users->village, true))): ?> checked <?php endif; ?>>
                                                            <label class="form-check-label"
                                                                for="village-<?php echo e($village->id); ?>">
                                                                <?php echo e($village->villageName); ?>

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


                                    <div class="row mt-3">
                                        <label  class="form-label fw-bold">Member Permission</label>
                                        <div class="col-sm-12 col-md-3">
                                            <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="savings"
                                                    <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('savings', (array) json_decode($users->memberPermision, true))): ?>
                                                            checked
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                    />
                                                <label class="form-check-label" >
                                                   Savings
                                                </label>
                                            </div>
                                            <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="loan"
                                                    <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('loan', (array) json_decode($users->memberPermision, true))): ?>
                                                        checked
                                                    <?php endif; ?>
                                                <?php endif; ?> />
                                                <label class="form-check-label" >
                                                   Loan
                                                </label>
                                            </div>
                                            <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="death"  <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('death', (array) json_decode($users->memberPermision, true))): ?>
                                                        checked
                                                    <?php endif; ?>
                                                <?php endif; ?>/>
                                                <label class="form-check-label" >
                                                   Death
                                                </label>
                                            </div>
                                            <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="meetings"  <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('meetings', (array) json_decode($users->memberPermision, true))): ?>
                                                        checked
                                                    <?php endif; ?>
                                                <?php endif; ?>/>
                                                <label class="form-check-label" >
                                                   Meetings
                                                </label>
                                            </div>
                                            <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="documents"  <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('documents', (array) json_decode($users->memberPermision, true))): ?>
                                                        checked
                                                    <?php endif; ?>
                                                <?php endif; ?>/>
                                                <label class="form-check-label" >
                                                   Documents
                                                </label>
                                            </div>
                                            <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="notes"  <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('notes', (array) json_decode($users->memberPermision, true))): ?>
                                                        checked
                                                    <?php endif; ?>
                                                <?php endif; ?>/>
                                                <label class="form-check-label" >
                                                   Notes
                                                </label>
                                            </div>
                                             <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="login"  <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('login', (array) json_decode($users->memberPermision, true))): ?>
                                                        checked
                                                    <?php endif; ?>
                                                <?php endif; ?>/>
                                                <label class="form-check-label" >
                                                   Login Details
                                                </label>
                                            </div>
                                               <div class="form-check">
                                                <input class="form-check-input division-checkbox" type="checkbox"
                                                    name="permissionsMember[]" value="location"  <?php if($users->memberPermision != null || $users->memberPermision != ''): ?>
                                                    <?php if($users->memberPermision && in_array('location', (array) json_decode($users->memberPermision, true))): ?>
                                                        checked
                                                    <?php endif; ?>
                                                <?php endif; ?>/>
                                                <label class="form-check-label" >
                                                   Location
                                                </label>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-12 text-center d-flex justify-content-end mt-3">
                                        <button type="submit" class="btn btn-primary me-3"
                                            value="updateuserdivisiondata">Update</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const divisionCheckboxes = document.querySelectorAll('.division-checkbox');

        divisionCheckboxes.forEach(function(divisionCheckbox) {
            divisionCheckbox.addEventListener('change', function() {
                const divisionId = this.id.replace('division-', '');
                const villageCheckboxes = document.querySelectorAll('.division-' + divisionId +
                    '-village');

                villageCheckboxes.forEach(function(villageCheckbox) {
                    villageCheckbox.checked = divisionCheckbox.checked;
                });
            });
        });
    });
</script>
<?php /**PATH /Users/anlex/Desktop/untitled folder/ngo/resources/views/pages/allpages/assign_division.blade.php ENDPATH**/ ?>