<?php
    $randomNumber = rand(1, 999999999);
    $formattedNumber = str_pad($randomNumber, 9, '0', STR_PAD_LEFT);
?>
<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> Create Member
                    </div>
                    <div class="card-body">
                        <div class="row mt-3">
                            <form id="usersForm" action="/createmembers" method="POST" enctype="multipart/form-data">
                                <?php echo csrf_field(); ?>

                                <?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">
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="title" class="form-label fw-bold">Title</label>
                                            <select id="title" name="title" class="form-control">
                                                <option value="Mr">Mr</option>
                                                <option value="Mrs">Mrs</option>
                                                <option value="Dr">Dr</option>
                                                <option value="Ms">Ms</option>
                                                <option value="Miss">Miss</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="firstName" class="form-label fw-bold">First Name</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('firstName')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="firstName" name="firstName" placeholder="Enter your first name"
                                                value="<?php echo e(old('firstName')); ?>" autofocus />
                                            <?php if($errors->has('firstName')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('firstName')); ?></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="lastName" class="form-label fw-bold">Last Name</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('lastName')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?> "
                                                id="lastName" name="lastName" value="<?php echo e(old('lastName')); ?>"
                                                placeholder="Enter your last name" autofocus />
                                            <?php if($errors->has('lastName')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('lastName')); ?></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="dateOfBirth" class="form-label fw-bold">DOB</label>
                                            <input type="date"
                                                class="form-control <?php if($errors->has('dateOfBirth')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="dateOfBirth" name="dateOfBirth" placeholder="Enter your dob"
                                                value="<?php echo e(old('dateOfBirth')); ?>" autofocus />
                                            <?php if($errors->has('dateOfBirth')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('dateOfBirth')); ?></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="address" class="form-label fw-bold">Address</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('address')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="address" name="address" placeholder="Enter your address"
                                                value="<?php echo e(old('address')); ?>" autofocus />
                                            <?php if($errors->has('address')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('address')); ?></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="nicNumber" class="form-label fw-bold">NIC Number</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('nicNumber')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="nicNumber" name="nicNumber" placeholder="Enter your user nic number"
                                                value="<?php echo e(old('nicNumber')); ?>" autofocus />
                                            <?php if($errors->has('nicNumber')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('nicNumber')); ?></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="nicIssueDate" class="form-label fw-bold">NIC Issue Date</label>
                                            <input type="date"
                                                class="form-control <?php if($errors->has('nicIssueDate')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="nicIssueDate" name="nicIssueDate"
                                                placeholder="Enter your user nic number"
                                                value="<?php echo e(old('nicIssueDate')); ?>" autofocus />
                                            <?php if($errors->has('nicIssueDate')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('nicIssueDate')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="newAccountNumber" class="form-label fw-bold">New Account
                                                Number</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('newAccountNumber')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="newAccountNumber" name="newAccountNumber"
                                                placeholder="Enter your new account number"
                                                value="<?php echo e(old('newAccountNumber', $formattedNumber)); ?>" autofocus
                                                readonly />
                                            <?php if($errors->has('newAccountNumber')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('newAccountNumber')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="oldAccountNumber" class="form-label fw-bold">Old Account
                                                Number</label>
                                            <input type="number"
                                                class="form-control <?php if($errors->has('oldAccountNumber')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="oldAccountNumber" name="oldAccountNumber"
                                                placeholder="Enter your user old account number"
                                                value="<?php echo e(old('oldAccountNumber')); ?>" autofocus />
                                            <?php if($errors->has('oldAccountNumber')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('oldAccountNumber')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="profession" class="form-label fw-bold">Profession</label>
                                            <select id="profession" name="profession"
                                                class="form-control <?php if($errors->has('profession')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>">
                                                <option value="">Select profession</option>
                                                <?php $__currentLoopData = $managePro; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($pro->id); ?>"><?php echo e($pro->name); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                            <?php if($errors->has('profession')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('profession')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>

                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="subprofession" class="form-label fw-bold">Sub
                                                Profession</label>
                                            <select id="subprofession" class="form-control" name="subprofession">
                                                <option value="">Select Sub Profession</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="gender" class="form-label fw-bold">Gender</label>
                                            <select id="gender" name="gender" class="form-control ">
                                                <option value="Male">Male</option>
                                                <option value="Female">Female</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="maritalStatus" class="form-label fw-bold">Marital
                                                Status</label>
                                            <select id="maritalStatus" name="maritalStatus" class="form-control">
                                                <option value="Single">Single</option>
                                                <option value="Married">Married</option>
                                                <option value="Divorced">Divorced</option>
                                                <option value="Widowed">Widowed</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="phoneNumber" class="form-label fw-bold">Phone Number</label>
                                            <input type="number"
                                                class="form-control  <?php if($errors->has('phoneNumber')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="phoneNumber" name="phoneNumber" value="<?php echo e(old('phoneNumber')); ?>"
                                                placeholder="Enter your user phone number" autofocus />
                                            <?php if($errors->has('phoneNumber')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('phoneNumber')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="profiePhoto" class="form-label fw-bold">Photo</label>
                                            <input type="file"
                                                class="form-control  <?php if($errors->has('profiePhoto')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="profiePhoto" name="profiePhoto" placeholder="select your photo"
                                                value="<?php echo e(old('profiePhoto')); ?>" accept=".jpg,.png" autofocus />
                                            <?php if($errors->has('profiePhoto')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('profiePhoto')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="signature" class="form-label fw-bold">Signature</label>
                                            <input type="file"
                                                class="form-control  <?php if($errors->has('signature')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="signature" name="signature" placeholder="select your signature"
                                                value="<?php echo e(old('signature')); ?>" accept=".jpg,.png" autofocus />
                                            <?php if($errors->has('signature')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('signature')); ?></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <hr>
                                    <h4 class="d-flex justify-content-center">Division By Village</h4>
                                    <div class="col-sm-12 col-md-6">
                                        <label for="divisionId" class="form-label fw-bold">Select Division</label>
                                        <select name="divisionId" id="divisionId"
                                            class="form-control <?php if($errors->has('divisionId')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>">
                                            <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($division->divisionName); ?>

                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                        <?php if($errors->has('divisionId')): ?>
                                            <div class="invalid-feedback"><?php echo e($errors->first('divisionId')); ?>

                                            </div>
                                        <?php endif; ?>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <label for="villageId" class="form-label fw-bold">Select Village</label>
                                        <select name="villageId" id="villageId" class="form-control">
                                            <option value="">Select Village</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-12 col-md-6 mt-3">
                                        <label for="smallGroup" class="form-label fw-bold">Small Group</label>
                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="smallGroup"
                                                id="smallGroupYes" value="Yes">
                                            <label class="form-check-label" for="smallGroupYes">Yes</label>
                                        </div>
                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="smallGroup"
                                                id="smallGroupNo" value="No" checked>
                                            <label class="form-check-label" for="smallGroupNo">No</label>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6 mt-3" id="selectSmallGroupDiv"
                                        style="display: none;">
                                        <label for="smallGroupId" class="form-label fw-bold">Select Small
                                            Group</label>
                                        <select name="smallGroupId" id="smallGroupId" class="form-control">
                                            <option value="">Select Small Group</option>
                                        </select>
                                    </div>
                                    <hr>
                                    <h4 class="d-flex justify-content-center">Division By GN</h4>
                                    <div class="col-sm-12 col-md-5">
                                        <label for="gnDivisionId" class="form-label fw-bold">GN Division</label>
                                        <select name="gnDivisionId" id="gnDivisionId" class="form-control">
                                            <option value="">Select GN Division</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-12 col-md-2 mt-3">
                                        <label for="smallGroup" class="form-label fw-bold">Small Group</label>
                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="smallGroupGN"
                                                id="smallGroupYesGN" value="Yes">
                                            <label class="form-check-label" for="smallGroupYes">Yes</label>
                                        </div>
                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="smallGroupGN"
                                                id="smallGroupNoGN" value="No" checked>
                                            <label class="form-check-label" for="smallGroupNo">No</label>
                                        </div>
                                    </div>

                                       <div class="col-sm-12 col-md-5 mt-3" id="selectSmallGroupDivGN"
                                        style="display: none;">
                                        <label for="smallGroupId" class="form-label fw-bold">Select Small
                                            Group</label>
                                        <select name="smallGroupIdGN" id="smallGroupIdGN" class="form-control">
                                            <option value="">Select Small Group</option>
                                        </select>
                                    </div>

                                </div>
                                <h4>A Follower</h4>
                                <hr>
                                <div class="row">
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="followerName" class="form-label fw-bold">Name</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('followerName')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="followerName" name="followerName" placeholder="enter your name"
                                                value="<?php echo e(old('followerName')); ?>" autofocus />
                                            <?php if($errors->has('followerName')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('followerName')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="followerAddress" class="form-label fw-bold">Address</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('followerAddress')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="followerAddress" name="followerAddress"
                                                placeholder="enter your address" value="<?php echo e(old('followerAddress')); ?>"
                                                autofocus />
                                            <?php if($errors->has('followerAddress')): ?>
                                                <div class="invalid-feedback"><?php echo e($errors->first('followerAddress')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="followerNicNumber" class="form-label fw-bold">NIC
                                                Number</label>
                                            <input type="text"
                                                class="form-control <?php if($errors->has('followerNicNumber')): ?> <?php echo e('is-invalid'); ?> <?php endif; ?>"
                                                id="followerNicNumber" name="followerNicNumber"
                                                placeholder="enter your nic number"
                                                value="<?php echo e(old('followerNicNumber')); ?>" autofocus />
                                            <?php if($errors->has('followerNicNumber')): ?>
                                                <div class="invalid-feedback">
                                                    <?php echo e($errors->first('followerNicNumber')); ?>

                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="col-sm-12 col-md-6">
                                        <div class="mb-6">
                                            <label for="followerIssueDate" class="form-label fw-bold">Issue
                                                Date</label>
                                            <input type="date" class="form-control " id="followerIssueDate"
                                                name="followerIssueDate" placeholder="enter your nic number"
                                                value="<?php echo e(old('followerIssueDate')); ?>" autofocus />
                                        </div>
                                    </div>
                                </div>

                                <div class="col mt-3 d-flex justify-content-end">
                                    <button class="btn btn-primary" type="submit" value="createmembers">Create
                                        Member</button>
                                </div>
                            </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    document.getElementById('divisionId').addEventListener('change', function() {
        var divisionId = this.value;

        if (divisionId) {
            fetch(`/get-villages/${divisionId}`)
                .then(response => response.json())
                .then(data => {
                    var villageSelect = document.getElementById('villageId');
                    villageSelect.innerHTML = '<option value="">Select Village</option>';

                    data.forEach(function(village) {
                        var option = document.createElement('option');
                        option.value = village.id;
                        option.text = village.villageName;
                        villageSelect.appendChild(option);
                    });
                })
                .catch(error => console.error('Error fetching villages:', error));

            fetch(`/get-gndivision/${divisionId}`)
                .then(response => response.json())
                .then(data => {
                    var villageSelect = document.getElementById('gnDivisionId');
                    villageSelect.innerHTML = '<option value="">Select Gn Division</option>';

                    data.forEach(function(gnDivision) {
                        var option = document.createElement('option');
                        option.value = gnDivision.id;
                        option.text = gnDivision.gnDivisionName;
                        villageSelect.appendChild(option);
                    });
                })
                .catch(error => console.error('Error fetching gnDivisionName:', error));
        } else {
            document.getElementById('villageId').innerHTML = '<option value="">Select Village</option>';
        }
    });

    document.getElementById('villageId').addEventListener('change', function() {
        var villageId = this.value;
        const divisionId = document.getElementById('divisionId');
        var divisionIdValue = divisionId.value;
        console.log(divisionIdValue);
        console.log(villageId);
        if (villageId) {
            fetch(`/get-smallgroup/${villageId}/${divisionIdValue}`)
                .then(response => response.json())
                .then(data => {
                    var villageSelect = document.getElementById('smallGroupId');
                    villageSelect.innerHTML = '<option value="">Select Small Group</option>';

                    data.forEach(function(smallGroup) {
                        var option = document.createElement('option');
                        option.value = smallGroup.id;
                        option.text = smallGroup.smallGroupName;
                        villageSelect.appendChild(option);
                    });
                })
                .catch(error => console.error('Error fetching villages:', error));
        } else {
            document.getElementById('smallGroupId').innerHTML = '<option value="">Select Small Group</option>';
        }
    });

        document.getElementById('gnDivisionId').addEventListener('change', function() {
        var villageId = this.value;
        const divisionId = document.getElementById('divisionId');
        var divisionIdValue = divisionId.value;
        console.log(divisionIdValue);
        console.log(villageId);
        if (villageId) {
            fetch(`/get-smallgroup-gn/${villageId}/${divisionIdValue}`)
                .then(response => response.json())
                .then(data => {
                    var villageSelect = document.getElementById('smallGroupIdGN');
                    villageSelect.innerHTML = '<option value="">Select Small Group</option>';

                    data.forEach(function(smallGroup) {
                        var option = document.createElement('option');
                        option.value = smallGroup.id;
                        option.text = smallGroup.smallGroupName;
                        villageSelect.appendChild(option);
                    });
                })
                .catch(error => console.error('Error fetching group:', error));
        } else {
            document.getElementById('smallGroupIdGN').innerHTML = '<option value="">Select Small Group</option>';
        }
    });

    document.getElementById('profession').addEventListener('change', function() {
        var professionId = this.value;
        if (professionId) {
            fetch(`/get-sub-profession/${professionId}`)
                .then(response => response.json())
                .then(data => {
                    var villageSelect = document.getElementById('subprofession');
                    villageSelect.innerHTML = '<option value="">Select sub profession</option>';

                    data.forEach(function(smallGroup) {
                        var option = document.createElement('option');
                        option.value = smallGroup.id;
                        option.text = smallGroup.name;
                        villageSelect.appendChild(option);
                    });
                })
                .catch(error => console.error('Error fetching sub profession:', error));
        } else {
            document.getElementById('subprofession').innerHTML =
                '<option value="">Select sub profession</option>';
        }
    });


    document.addEventListener('DOMContentLoaded', function() {
        const radioButtons = document.querySelectorAll('input[name="smallGroup"]');
        const selectSmallGroupDiv = document.getElementById('selectSmallGroupDiv');
        radioButtons.forEach(radio => {
            radio.addEventListener('change', function() {
                const selectedValue = document.querySelector('input[name="smallGroup"]:checked')
                    .value;
                if (selectedValue == 'Yes') {
                    selectSmallGroupDiv.style.display = 'block';
                } else {
                    selectSmallGroupDiv.style.display = 'none';
                }
            });
        });
    });

        document.addEventListener('DOMContentLoaded', function() {
        const radioButtons = document.querySelectorAll('input[name="smallGroupGN"]');
        const selectSmallGroupDiv = document.getElementById('selectSmallGroupDivGN');
        radioButtons.forEach(radio => {
            radio.addEventListener('change', function() {
                const selectedValue = document.querySelector('input[name="smallGroupGN"]:checked')
                    .value;
                if (selectedValue == 'Yes') {
                    selectSmallGroupDiv.style.display = 'block';
                } else {
                    selectSmallGroupDiv.style.display = 'none';
                }
            });
        });
    });

    document.addEventListener('DOMContentLoaded', function() {
        const gnDivRadio = document.querySelectorAll('input[name="gnDiv"]');
        gnDivRadio.forEach(radio => {
            radio.addEventListener('change', function() {
                const selectedValue = document.querySelector('input[name="gnDiv"]:checked')
                    .value;
                if (selectedValue == 'Yes') {
                    const divisionId = document.getElementById('divisionId');
                    var divisionIdValue = divisionId.value;
                    console.log(divisionIdValue);
                    if (divisionIdValue) {
                        fetch(`/get-smallgroup-by-gn/${divisionIdValue}`)
                            .then(response => response.json())
                            .then(data => {
                                var villageSelect = document.getElementById('smallGroupId');
                                villageSelect.innerHTML =
                                    '<option value="">Select Small Group</option>';

                                data.forEach(function(allSmallGroups) {
                                    var option = document.createElement('option');
                                    option.value = allSmallGroups.id;
                                    option.text = allSmallGroups.smallGroupName;
                                    villageSelect.appendChild(option);
                                });
                            })
                            .catch(error => console.error('Error fetching villages:', error));
                    } else {
                        document.getElementById('smallGroupId').innerHTML =
                            '<option value="">Select Small Group</option>';
                    }
                } else {
                    var villageId = document.getElementById('villageId');
                    const divisionId = document.getElementById('divisionId');
                    var divisionIdValue = divisionId.value;
                    var villageId = villageId.value;
                    console.log(divisionIdValue);
                    console.log(villageId);
                    if (villageId) {
                        fetch(`/get-smallgroup/${villageId}/${divisionIdValue}`)
                            .then(response => response.json())
                            .then(data => {
                                var villageSelect = document.getElementById('smallGroupId');
                                villageSelect.innerHTML =
                                    '<option value="">Select Small Group</option>';

                                data.forEach(function(smallGroup) {
                                    var option = document.createElement('option');
                                    option.value = smallGroup.id;
                                    option.text = smallGroup.smallGroupName;
                                    villageSelect.appendChild(option);
                                });
                            })
                            .catch(error => console.error('Error fetching villages:', error));
                    } else {
                        document.getElementById('smallGroupId').innerHTML =
                            '<option value="">Select Small Group</option>';
                    }
                }
            });
        });
    });
</script>
<?php /**PATH /home/techhdyz/swd.technathi.cloud/resources/views/pages/allpages/create_member.blade.php ENDPATH**/ ?>