<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">
                        <div class="col-6">
                            <i class="menu-icon ti ti-users-group"></i> Manage Member
                        </div>
                        <?php if($userType == 'superAdmin'): ?>
                            <div class="col-6 d-flex justify-content-end">
                                <button class="btn btn-success btn-sm me-2" data-bs-toggle="modal"
                                    data-bs-target="#importMemberModal"><i
                                        class="menu-icon ti ti-square-rounded-plus"></i> Import Member</button>
                                <a href="/create_member">
                                    <button class="btn btn-success btn-sm"><i
                                            class="menu-icon ti ti-square-rounded-plus"></i> Create Member</button>
                                </a>
                            </div>
                        <?php else: ?>
                            <?php
                                $userRolesArray = $getUserRole->pluck('roleName')->toArray();
                            ?>
                            <?php if(in_array($userType, $userRolesArray)): ?>
                                <?php
                                    $usersDataPer = $permissions;
                                    $usersDataPer = json_decode($usersDataPer, true);
                                ?>

                                <div class="col-6 d-flex justify-content-end">
                                    <?php if(in_array('importMember', $usersDataPer)): ?>
                                        <button class="btn btn-success btn-sm me-2" data-bs-toggle="modal"
                                            data-bs-target="#importMemberModal"><i
                                                class="menu-icon ti ti-square-rounded-plus"></i> Import Member</button>
                                    <?php endif; ?>
                                    <?php if(in_array('addMember', $usersDataPer)): ?>
                                        <a href="/create_member">
                                            <button class="btn btn-success btn-sm"><i
                                                    class="menu-icon ti ti-square-rounded-plus"></i> Create
                                                Member</button>
                                        </a>
                                    <?php endif; ?>
                                </div>
                            <?php endif; ?>
                        <?php endif; ?>

                    </div>
                    <div class="card-body">
                        <div class="row mt-3">
                            <form method="GET" action="<?php echo e(route('filter_members_by_village')); ?>"
                                class="d-flex justify-content-between w-100">
                                <div class="col-md-3 me-2">
                                    <div class="form-group">
                                        <label for="divisionId" class="form-label fw-bold">Select Division</label>
                                        <select name="divisionId" id="divisionId" class="form-control"
                                            onchange="this.form.submit()">
                                            <option value="">Select Division</option>
                                            <?php $__currentLoopData = $getDivision; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $division): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($division->id); ?>"
                                                    <?php echo e(request('divisionId') == $division->id ? 'selected' : ''); ?>>
                                                    <?php echo e($division->divisionName); ?>

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

                                <div class="col-md-3 me-2">
                                    <div class="form-group">
                                        <label for="villageId" class="form-label fw-bold">Select Village</label>
                                        <select name="villageId" id="villageId" class="form-control"
                                            onchange="this.form.submit()">
                                            <option value="">Select Village</option>
                                            <?php $__currentLoopData = $villages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $village): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($village->id); ?>"
                                                    <?php echo e(request('villageId') == $village->id ? 'selected' : ''); ?>>
                                                    <?php echo e($village->villageName); ?>

                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3 me-2">
                                    <div class="form-group">
                                        <label for="professionName" class="form-label fw-bold">Select Profession</label>
                                        <select name="professionName" id="professionName" class="form-control"
                                            onchange="this.form.submit()">
                                            <option value="">Select Profession</option>
                                            <?php $__currentLoopData = $getProfession; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $profession): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($profession->name); ?>"
                                                    <?php echo e(request('professionName') == $profession->name ? 'selected' : ''); ?>>
                                                    <?php echo e($profession->name); ?>

                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3 me-2" id="selectSmallGroupDiv" style="display: none;">
                                    <div class="form-group">
                                        <label for="smallGroupId" class="form-label fw-bold">Select Small Group</label>
                                        <select name="smallGroupId" id="smallGroupId" class="form-control"
                                            onchange="this.form.submit()">
                                            <option value="">Select Small Group</option>
                                            <?php $__currentLoopData = $smallGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $smallGroup): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($smallGroup->id); ?>"
                                                    <?php echo e(request('smallGroupId') == $smallGroup->id ? 'selected' : ''); ?>>
                                                    <?php echo e($smallGroup->smallGroupName); ?>

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


                            </form>
                        </div>



                        <div class="row mt-3">
                            <table class="table table-sm " id="memberTable">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Name</th>
                                        <th>NIC number</th>
                                        <th>Division</th>
                                        <th>Village</th>
                                        <th>Small Group</th>
                                        <th>Profession</th>
                                        <th>Old Account Number</th>
                                        <th>Status Type</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?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; ?>
                                    <?php
                                        $count = 1;
                                    ?>
                                    <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $encryptedId = encrypt($member->id);
                                        ?>
                                        <?php if(auth()->user()->userType == 'superAdmin'): ?>
                                            <tr>
                                                <td><?php echo e($count++); ?></td>
                                                <td> <a href="<?php echo e(route('view_member', $encryptedId)); ?>">
                                                        <?php echo e($member->firstName); ?> <?php echo e($member->lastName); ?></a></td>
                                                <td><?php echo e($member->nicNumber); ?></td>
                                                <td>
                                                    <?php if($member->divisionId == ''): ?>
                                                        -
                                                    <?php else: ?>
                                                    <?php
                                                        $divIdEnc = Crypt::encrypt($member->divisionId);
                                                    ?>
                                                      <a href="<?php echo e(route('division_details', $divIdEnc)); ?>">  <?php echo e($member->division->divisionName); ?> </a>
                                                    <?php endif; ?>
                                                </td>
                                                <td>
                                                    <?php if($member->villageId == ''): ?>
                                                        -
                                                    <?php else: ?>
                                                    <?php
                                                        $villageIdEnc = Crypt::encrypt($member->villageId);
                                                    ?>
                                                        <a href="<?php echo e(route('village_details', $villageIdEnc)); ?>"> <?php echo e($member->village->villageName); ?> </a>
                                                    <?php endif; ?>
                                                </td>
                                                <?php if($member->smallGroupId == ''): ?>
                                                    <td>-</td>
                                                <?php else: ?>
                                                <?php
                                                    $smallgroupIdEnc = Crypt::encrypt($member->smallGroupId);
                                                ?>
                                                    <td>
                                                        <a href="<?php echo e(route('smallgroup_details', $smallgroupIdEnc)); ?>"><?php echo e($member->smallgroup->smallGroupName); ?> </a></td>
                                                <?php endif; ?>
                                                <td>
                                                    <?php $__currentLoopData = $getProfession; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <?php if($pro->id == $member->profession): ?>
                                                            <?php echo e($pro->name); ?>

                                                        <?php endif; ?>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </td>
                                                <td><?php echo e($member->oldAccountNumber); ?></td>
                                                <td><?php echo e($member->statusType); ?></td>
                                                <td>
                                                    <?php if($member->status == 1): ?>
                                                        <span class="badge bg-label-success">Active</span>
                                                    <?php else: ?>
                                                        <span class="badge bg-label-danger">Inactive</span>
                                                    <?php endif; ?>
                                                </td>
                                                <td>
                                                    <div class="dropdown">
                                                        <button type="button"
                                                            class="btn p-0 dropdown-toggle hide-arrow"
                                                            data-bs-toggle="dropdown">
                                                            <i class="ti ti-dots-vertical"></i>
                                                        </button>
                                                        <div class="dropdown-menu">
                                                            <a class="dropdown-item"
                                                                href="<?php echo e(route('view_member', $encryptedId)); ?>"><i
                                                                    class="ti ti-eye me-1"></i> View</a>
                                                            <a class="dropdown-item"
                                                                href="<?php echo e(route('update_member', $encryptedId)); ?>"><i
                                                                    class="ti ti-pencil me-1"></i> Edit</a>
                                                            <a class="dropdown-item btnshowStatusModal"
                                                                data-id="<?php echo e($member->id); ?>" href="#"><i
                                                                    class="ti ti-edit me-1"></i> Change Status</a>

                                                            

                                                        </div>
                                                    </div>
                                                </td>
                                            </tr>
                                        <?php else: ?>
                                            <?php
                                                $divArray = auth()->user()->division;
                                                $vilArray = auth()->user()->village;
                                            ?>
                                            <?php if($divArray != '' || $divArray != null || $vilArray != '' || $vilArray != null): ?>
                                                <?php if(in_array($member->divisionId, json_decode(auth()->user()->division)) &&
                                                        in_array($member->villageId, json_decode(auth()->user()->village))): ?>
                                                    <tr>
                                                        <td><?php echo e($count++); ?></td>
                                                        <td>
                                                            <?php if($userType != 'superAdmin'): ?>
                                                                <?php if(in_array('viewMember', $usersDataPer)): ?>
                                                                    <a href="<?php echo e(route('view_member', $encryptedId)); ?>">
                                                                        <?php echo e($member->firstName); ?></a>
                                                                <?php else: ?>
                                                                    <?php echo e($member->firstName); ?>

                                                                <?php endif; ?>
                                                            <?php else: ?>
                                                                <a href="<?php echo e(route('view_member', $encryptedId)); ?>">
                                                                    <?php echo e($member->firstName); ?></a>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td><?php echo e($member->nicNumber); ?></td>
                                                        <td><?php echo e(empty($member->division->divisionName) ? 'N/A' : $member->division->divisionName); ?>

                                                        </td>
                                                        <td><?php echo e(empty($member->village->villageName) ? 'N/A' : $member->village->villageName); ?>

                                                        </td>
                                                        <?php if($member->smallGroupId == ''): ?>
                                                            <td>-</td>
                                                        <?php else: ?>
                                                            <td><?php echo e($member->smallgroup->smallGroupName); ?></td>
                                                        <?php endif; ?>
                                                        <td><?php echo e($member->profession); ?></td>
                                                        <td><?php echo e($member->oldAccountNumber); ?></td>
                                                        <td><?php echo e($member->uniqueId); ?></td>
                                                        <td><?php echo e($member->statusType); ?></td>
                                                        <td>
                                                            <?php if($member->status == 1): ?>
                                                                <span class="badge bg-label-success">Active</span>
                                                            <?php else: ?>
                                                                <span class="badge bg-label-danger">Inactive</span>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td>
                                                            <div class="dropdown">
                                                                <button type="button"
                                                                    class="btn p-0 dropdown-toggle hide-arrow"
                                                                    data-bs-toggle="dropdown">
                                                                    <i class="ti ti-dots-vertical"></i>
                                                                </button>
                                                                <div class="dropdown-menu">
                                                                    <?php if($userType != 'superAdmin'): ?>
                                                                        <?php if(in_array('viewMember', $usersDataPer)): ?>
                                                                            <a class="dropdown-item"
                                                                                href="<?php echo e(route('view_member', $encryptedId)); ?>"><i
                                                                                    class="ti ti-eye me-1"></i>
                                                                                View</a>
                                                                        <?php endif; ?>
                                                                    <?php else: ?>
                                                                        <a class="dropdown-item"
                                                                            href="<?php echo e(route('view_member', $encryptedId)); ?>"><i
                                                                                class="ti ti-eye me-1"></i> View</a>
                                                                    <?php endif; ?>

                                                                    <?php if($userType != 'superAdmin'): ?>
                                                                        <?php if(in_array('ManageMemberEdit', $usersDataPer)): ?>
                                                                            <a class="dropdown-item"
                                                                                href="<?php echo e(route('update_member', $encryptedId)); ?>"><i
                                                                                    class="ti ti-pencil me-1"></i>
                                                                                Edit</a>
                                                                        <?php endif; ?>
                                                                    <?php else: ?>
                                                                        <a class="dropdown-item"
                                                                            href="<?php echo e(route('update_member', $encryptedId)); ?>"><i
                                                                                class="ti ti-pencil me-1"></i> Edit</a>
                                                                    <?php endif; ?>

                                                                    <a class="dropdown-item btnshowStatusModal"
                                                                        href="#"
                                                                        data-id="<?php echo e($member->id); ?>"><i
                                                                            class="ti ti-eye me-1"></i> Change
                                                                        Status</a>

                                                                    
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="confirmModal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="confirmModalLabel">Confirm Deletion</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                Are you sure you want to delete this member?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-danger" id="confirmDeleteBtn">Delete</button>
            </div>
        </div>
    </div>
</div>


<script>
    document.addEventListener('DOMContentLoaded', function() {
        var divisionId = document.getElementById('divisionId');
        var villageId = document.getElementById('villageId');
        var smallGroupDiv = document.getElementById('selectSmallGroupDiv');

        function toggleSmallGroupDropdown() {
            if (divisionId.value || villageId.value) {
                smallGroupDiv.style.display = 'block';
            } else {
                smallGroupDiv.style.display = 'none';
            }
        }

        toggleSmallGroupDropdown();

        divisionId.addEventListener('change', toggleSmallGroupDropdown);
        villageId.addEventListener('change', toggleSmallGroupDropdown);
    });
</script>


<!-- Import member Modal -->
<div class="modal fade" id="importMemberModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-simple">
        <div class="modal-content">
            <div class="modal-body">
                <button type="button" class="btn-close btn-pinned" data-bs-dismiss="modal"
                    aria-label="Close"></button>
                <div class="text-center mb-4">
                    <h4 class="mb-2">Import Member</h4>
                    <p>Member import function</p>
                </div>

                <!-- Sample Excel Download -->
                <div class="col-12 mb-3 text-center">
                    <a href="<?php echo e(asset('excelimportfile/member.xlsx')); ?>" class="btn btn-outline-info" download>
                        Download Sample Excel
                    </a>
                </div>

                <!-- File Input -->
                <div class="col-12 mb-4">
                    <label class="form-label" for="txtImportFile">Choose Excel file</label>
                    <input type="file" id="txtImportFile" class="form-control" accept=".xlsx, .xls, .csv" />
                </div>

                <!-- Action Buttons -->
                <div class="col-12 text-center demo-vertical-spacing">
                    <button class="btn btn-primary me-4" id="btnImportMember">Import Member</button>
                    <button type="reset" class="btn btn-label-secondary" data-bs-dismiss="modal"
                        aria-label="Close">
                        Discard
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--/ Import member Modal -->


<!-- Change Status  Modal -->
<div class="modal fade" id="changeStatusModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-simple">
        <div class="modal-content">
            <div class="modal-body">
                <button type="button" class="btn-close btn-pinned" data-bs-dismiss="modal"
                    aria-label="Close"></button>
                <div class="text-center mb-4">
                    <h4 class="mb-2">Change Status</h4>
                    <p>Change Status function</p>
                </div>

                <input type="text" id="txtMemberId" hidden>

                <div class="col-12 mb-4">
                    <label class="form-label">Status</label>
                    <select class="selectize" id="txtStatus">
                        <option value="">---Select---</option>
                        <option value="1">Active</option>
                        <option value="0">In Active</option>
                    </select>
                </div>

                <div class="col-12 mb-4" hidden id="txtStatusTypeDiv">
                    <label class="form-label">Status Type</label>
                    <select class="selectize" id="txtStatusType">
                        <option value="Loan Member">Loan Member</option>
                        <option value="Saving Member">Saving Member</option>
                    </select>
                </div>

                <!-- Action Buttons -->
                <div class="col-12 text-center demo-vertical-spacing">
                    <button class="btn btn-primary me-4" id="btnChangeStatusMember">Change Status Member</button>
                    <button type="reset" class="btn btn-label-secondary" data-bs-dismiss="modal"
                        aria-label="Close">
                        Discard
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--/ Change Status Modal -->
<?php /**PATH /home/techhdyz/swd.technathi.cloud/resources/views/pages/allpages/manage_member.blade.php ENDPATH**/ ?>