<style>
    .table-header-background{
        background-color: #d9cdcd
    }
    #mira-women-list{
        border: 2px solid #dddddd;
    }
    #mira-women-list > thead > tr > th,
    #mira-women-list > tbody > tr > th,
    #mira-women-list > tfoot > tr > th,
    #mira-women-list > thead > tr > td,
    #mira-women-list > tbody > tr > td,
    #mira-women-list > tfoot > tr > td {
        border: 2px solid #dddddd;

    }
    #mira-women-list{
        width: 100%;
        overflow-x: scroll;
    }

    .back-btn-style
    {
        float:right;
        margin-bottom: -10px;
    }
   

</style>

<script>
    var baseUrl = "<?php echo base_url(); ?>"
</script>
<?php
$ashaName = 'Testing';
$level = $this->session->userdata('level');
$asharegion=$this->session->userdata('asharegionId');
$anmregion=$this->session->userdata('anmregionId');

?>
<div class="panel"> 
  
    <div class="panel-body" style="margin-top: -16px">
         <div class="col text-left bg-info">
                    <h3 class="text-info" style=" width: 300px; float:left;"><strong>Registered&nbsp;Women&nbsp;List</strong></h3>
                     <?php  $regionId=$this->session->userdata('regionId'); ?>
      <?php 
      if(isset($flag) && $flag == false){
         if($level==1){
        
        ?>
        
        <!-- <a class="btn btn-primary back-btn-style" href="</?php echo base_url('registrationhousewomenchild/backmethodcalling')?>">Back</a>
     </?php  }else {?>
                <a class="btn btn-primary back-btn-style" href="</?php echo base_url('registrationhousewomenchild/getHouseListByRegionID/'.$regionId.'/'.$ashaName )?>">Back</a>
            --> <?php }}?>
            <button type="button" class="btn btn-primary back-btn-style" onclick="window.history.back();">Back</button>
       </div>
        
        <table id="mira-women-list" class="table table-bordred table-striped table-hover">
            <thead>
            <?php if($level==1){
                if($flag==true){
                ?>
                <tr>
                <th colspan="10">
                    <div class="row" style="margin-left: 2px">
                            <div class="row">
                <div class="col-md-4">
                    <div class="form-group">
                    <div class="input-group">
                        <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select ANM</strong></span>
                        <select name="anm_region_code" id="anm_region_code" class="form-control">
                            <option value="0" selected="true" disabled=""> Select ANM</option>
                            <?php
                            for ($i = 0; $i < count($anmList); $i++) {
                                if (isset($regionCode)) {
                                    if ($anmselected == $anmList[$i]['region_code']) {
                                        ?>
                                        <option selected="true" value=<?= $anmList[$i]['region_code'] ?> ><strong><?= $anmList[$i]['user_name'] ?></strong></option>
                                    <?php } else { ?>
                                        <option value=<?= $anmList[$i]['region_code'] ?>><strong><?= $anmList[$i]['user_name'] ?></strong></option>
                                        <?php
                                    }
                                } else {
                                    ?>
                                    <option value=<?= $anmList[$i]['region_code'] ?>><strong><?= $anmList[$i]['user_name'] ?></strong></option>
                                    <?php
                                }
                            }
                            ?>
                        </select>
                        <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                    </div>                    
                </div>   
                </div>
                </div>
                    </div>
                    
                <div class="row" style="margin-top: 10px">
                <?php  if (isset($miraList) and $miraList and $level==1) { ?>
                <div class="col-md-4">
                <div class="form-group">
                    <div class="input-group">
                        <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select Asha</strong></span>
                        <select name="region_code" id="region_code" class="form-control">
                            <option value=0 selected="true" disabled=""> Select Asha</option>
                            <?php
                            for ($i = 0; $i < count($miraList); $i++) {
                                if (isset($regionCode)) {
                                    if ($ashaselected == $miraList[$i]['region_code']) {
                                        ?>
                                        <option selected="true" value=<?= $miraList[$i]['region_code'] ?> ><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                    <?php } else { ?>
                                        <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                        <?php
                                    }
                                } else {
                                    ?>
                                    <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                    <?php
                                }
                            }
                            ?>
                        </select>
                        <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                    </div>                    
                </div> 
                </div>
                <?php  }else {?> 
                <div class="col-md-4">
                <div class="form-group">
                    <div class="input-group">
                        <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select Asha</strong></span>
                        <select name="region_code" id="region_code" class="form-control">
                            <option value="0" selected="true" disabled=""> Select Asha</option>
                            
                        </select>
                        <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                    </div>                    
                </div> 
                </div>
                <?php }?>
                <div class="col-lg-1 col-lg-push-3" id="asha_list_update_spinner" style="display: none;margin-left: -10px;margin-top: 6px">
                <i class="fa fa-spinner fa-spin"></i>
                </div>
                <div class="col-md-4">
                <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i aria-hidden="true"></i><strong>Search By</strong></span>
                    <select name="searchbydate" id="searchbydate" required class="form-control">
                        <option value="0" disabled="true" selected="true"> Select Option</option>
                        <option value="1"> <strong>By Mobile Date</strong></option>
                        <option value="2"> <strong>By Actual Date</strong></option>
                        <option value="3"><strong>By Server Date</strong></option>
                    </select>
                    <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                </div>                    
                </div> 
                </div>

                <div class="col-md-2-push-2" id="trdspan" style="display: none;"> 
                <label ><b>Total Records:</b><span id="trd" ></span></label>
                </div>
                <div class="col-md-2-push-2" style="display: none;" id="frdspan"> 
                <label><b>Filtered Records:</b><span id="frd" ></span></label>
                </div>
                </div>

                <div class="row">
                <div class="col-lg-4">   

                <div class="form-group">
                <div class="input-group date" id="st_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                    <span class="input-group-addon"><strong>Start Date</strong></span>
                    <input class="form-control" type="text" name="st_date" id="st_date_input"   required placeholder="dd-mm-yyyy">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>                    
                </div>

                </div>
                <div class="col-lg-4">   

                <div class="form-group">
                <div class="input-group date" id="en_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                    <span class="input-group-addon"><strong>End Date</strong></span>
                    <input class="form-control" type="text" name="en_date" id="en_date_input"  required placeholder="dd-mm-yyyy">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>                    
                </div>

                </div>
                
                <div class="col-lg-4">
                <input type="button" class="btn btn-primary" id="btnsearch" value="Submit">
                </div>
                        
                </div>
                </th>
                </tr>
                        <?php }} ?>

                <?php  if (isset($miraList) and $miraList and $level>1) { ?>
                <tr>
                <th colspan="10">
                <div class="row" style="margin-top: 10px">
                <div class="col-md-4">
                <div class="form-group">
                    <div class="input-group">
                        <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select Asha</strong></span>
                        <select name="region_code" id="region_code" class="form-control">
                            <option value="0" selected="true" disabled=""> Select Asha</option>
                            <?php
                            for ($i = 0; $i < count($miraList); $i++) {
                                if (isset($regionCode)) {
                                    if ($regionCode == $miraList[$i]['region_code']) {
                                        ?>
                                        <option selected="true" value=<?= $miraList[$i]['region_code'] ?> ><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                    <?php } else { ?>
                                        <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                        <?php
                                    }
                                } else {
                                    ?>
                                    <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                    <?php
                                }
                            }
                            ?>
                        </select>
                        <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                    </div>                    
                </div> 
                </div>
                <div class="col-lg-1 col-lg-push-3" id="house_list_update_spinner" style="display: none;margin-left: -10px;margin-top: 6px">
                <i class="fa fa-spinner fa-spin"></i>
                </div>
                <div class="col-md-4">
                <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i aria-hidden="true"></i><strong>Search By</strong></span>
                    <select name="searchbydate" id="searchbydate" required class="form-control">
                        <option value="0" disabled="true" selected="true"> Select Option</option>
                        <option value="1"> <strong>By Mobile Date</strong></option>
                        <option value="2"> <strong>By Actual Date</strong></option>
                        <option value="3"><strong>By Server Date</strong></option>
                    </select>
                    <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                </div>                    
                </div> 
                </div>

                <div class="col-md-2-push-2" id="trdspan" style="display: none;"> 
                <label ><b>Total Records:</b><span id="trd" ></span></label>
                </div>
                <div class="col-md-2-push-2" style="display: none;" id="frdspan"> 
                <label><b>Filtered Records:</b><span id="frd" ></span></label>
                </div>
                </div>

                <div class="row">
                <div class="col-lg-4">   

                <div class="form-group">
                <div class="input-group date" id="st_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                    <span class="input-group-addon"><strong>Start Date</strong></span>
                    <input class="form-control" type="text" name="st_date" id="st_date_input" required placeholder="dd-mm-yyyy">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>                    
                </div>

                </div>
                <div class="col-lg-4">   

                <div class="form-group">
                <div class="input-group date" id="en_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                    <span class="input-group-addon"><strong>End Date</strong></span>
                    <input class="form-control" type="text" name="en_date" id="en_date_input" required placeholder="dd-mm-yyyy">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>                    
                </div>

                </div>
                
                <div class="col-lg-4">
                <input type="button" class="btn btn-primary" id="btnsearch" value="Submit">
                </div>
                        
                </div>
                </th>
                </tr>


                <?php }?>
            <tr class="table-header-background">
                <th class="text-center">#</th>
                <th class="text-center">Women&nbsp;ID</th>
                <th class="text-center">Women&nbsp;Name</th>
                <th class="text-center">Actual&nbsp;Registration&nbsp;Date</th>
                <th class="text-center">House&nbsp;No.</th>
                <th class="text-center">House&nbsp;Head</th>
                <th class="text-center">Husband&nbsp;Name</th>               
                <th class="text-center">Pregnant&nbsp;Status</th>
            </tr>
            </thead>
            <tbody>
                <?php
                if(isset($womenListHouse))
                {
                   $womenList= $womenListHouse; 
                }
              
                
                if (isset($womenList) and $womenList and $womenList!=NULL ) {
                    for ($i = 0; $i < count($womenList); $i++) {
                        ?>
                        <tr id="<?='w'.$womenList[$i]['women_id']?>">
                            <td class="text-center"><?= ($i + 1) ?></td>
                             <td class="text-center">

                                <!-- make wrking href -->
                                <a href="<?php echo base_url('registrationhousewomenchild/getChildrenListByWomenId/'.$womenList[$i]['women_id'])?>">
                                    <?= "W".$womenList[$i]['women_id'] ?>
                                </a>

                              </td>
                            
                      
                            <td class="text-center"><?= $womenList[$i]['name'] ?></td>
                            <td class="text-center"><?= date('d-m-Y', strtotime($womenList[$i]['create_date'])); ?></td>
                            <td class="text-center"><?= str_replace(' ', '&nbsp;', $womenList[$i]['house_number']) ?></td>
                            <td class="text-center"><?= str_replace(' ', '&nbsp;', $womenList[$i]['house_head_name']) ?></td>
                            <td class="text-center"><?= $womenList[$i]['husband'] ?></td>
                            <?php if ($womenList[$i]['pregnant_status'] == 1) { ?>
                                <td class="text-center"><span class="label label-success">Pregnant</span></td>
                            <?php } else { ?>
                                <td class="text-center"><span class="label label-primary">Other&nbsp;Women</span></td>   
                            <?php } ?>
                       
                            

                        </tr>
                        <?php
                    }
                }
                ?>

            </tbody>
        </table>

    </div>
    <div class="panel-footer" style="margin-top: -36px">
        <h4 id="no-data" class="text-center text-danger" style="display: none;">
            <b>* Data not found . . !</b>
        </h4>
        <div class="row">
            <div class="col-lg-12">
                <ul class="pagination pagination-large" id="pagination">
                    
                </ul>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="womenDelete" tabindex="-1" role="dialog" aria-labelledby="Delete" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close btn-danger" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
                <h3 class="modal-title custom_align text-center" id="Heading">Delete Women</h3>
            </div>
            <div class="modal-body">
                <input id="women_id" type="hidden" name="women_id" value="">
                <h4 class="text-center text-danger"><strong>Are you sure you want to delete this Record?</strong></h4>
            </div>
            <div class="modal-footer ">
                <button id="yes_women" type="button" class="btn btn-success" ><span class="glyphicon glyphicon-ok-sign"></span> Yes</button>
                <button id="no_women" type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
            </div>
        </div>

    </div>

</div>

<script type="text/javascript">
    $(document).ready(function () {
         $('.women-delete-data').click(function () {
            $('#women_id').val($(this).val());
           
           var posY = $(this).position().top;
            $('#womenDelete').css({'margin-top' :300});
            $('#womenDelete').css({'margin-left' :530});
            

        });
        
         //***********************************************//
        $('#yes_women').click(function () {
            var womenId = $('#women_id').val();

            $.ajax({
                url: '<?= base_url('women-delete') ?>',
                data: {
                    women_id: womenId
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    var women_update_data = JSON.parse(data);
                    if (women_update_data['status']) {
                        $('#w' + women_update_data['women_id']).remove();
                        $('#womenDelete').modal('hide');
                        
                    }
                }
            });
        });

        $('#region_code').change(function () {
            var region_code = parseInt($('#region_code').val());       
            $('#women_list_update_spinner').css('display', 'block');
            $('#mira-women-list tbody tr').remove();
            $('#pagination li').remove();

            $('#st_date_input').val('');
            $('#en_date_input').val('');
            $("#trd").text(0);
            $("#frd").text('0');
            $('#searchbydate option:first').prop('selected', true);

            $.ajax({
                url: '<?= base_url('women_list_view_jquery') ?>',
                data: {
                    region_code: region_code
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    $('#women_list_update_spinner').css('display', 'none');
                    $('#no-data').css('display', 'none');
                    let women_data;
                    try{
                        women_data = JSON.parse(data);
                        console.log(women_data);
                        if (women_data['womenList']) {
                            $("#trd").text(women_data['totalRecords']);
                            $('#trdspan').css('display', 'block');
                            for (var i = 0; i < women_data['womenList'].length; i++) {
                                $("#mira-women-list tbody").append('<tr></tr>');
                                var date_string = getDateFormat(women_data['womenList'][i]['create_date']);
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + (parseInt(i) + 1) + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center"><a href="' + baseUrl + 'registrationhousewomenchild/getChildrenListByWomenId/' + women_data['womenList'][i]['women_id'] + '">' + "W" + women_data['womenList'][i]['women_id'] + '</a></td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['name'] + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + date_string + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['house_number'] + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['house_head_name'] + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['husband'] + '</td>');                    
                                if (parseInt(women_data['womenList'][i]['pregnant_status']) === 1) {
                                    $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Pregnant" + '</span></td>');
                                } else {
                                    $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Unpregnant" + '</span></td>');
                                }
                            
                            }
                        }
                        
                        if(women_data['totalPage'] && parseInt(women_data['totalPage']) > 1){

                            let totalPages = parseInt(women_data['totalPage']);
                            const pagination = document.getElementById('pagination');

                            // Create previous button
                            const prevLi = document.createElement('li');
                            prevLi.className = 'page-item';
                            const prevLink = document.createElement('a');
                            prevLink.className = 'page-link';
                            prevLink.href = '#';
                            prevLink.setAttribute('aria-label', 'Previous');
                            const prevSpan = document.createElement('span');
                            prevSpan.setAttribute('aria-hidden', 'true');
                            prevSpan.innerHTML = '&laquo;';
                            prevLink.appendChild(prevSpan);
                            prevLi.appendChild(prevLink);
                            pagination.appendChild(prevLi);

                            // Create numeric page buttons using a for loop
                            for (let i = 1; i <= totalPages; i++) {
                                const pageLi = document.createElement('li');
                                pageLi.className = 'page-item';
                                const pageLink = document.createElement('a');
                                pageLink.className = 'page-link';
                                pageLink.href = '#';
                                pageLink.onclick = function() {
                                    getDataUsingPagination(i, region_code);
                                };
                                pageLink.textContent = i;
                                pageLi.appendChild(pageLink);
                                pagination.appendChild(pageLi);
                            }

                            // Create next button
                            const nextLi = document.createElement('li');
                            nextLi.className = 'page-item';
                            const nextLink = document.createElement('a');
                            nextLink.className = 'page-link';
                            nextLink.href = '#';
                            nextLink.setAttribute('aria-label', 'Next');
                            const nextSpan = document.createElement('span');
                            nextSpan.setAttribute('aria-hidden', 'true');
                            nextSpan.innerHTML = '&raquo;';
                            nextLink.appendChild(nextSpan);
                            nextLi.appendChild(nextLink);
                            pagination.appendChild(nextLi);
                        }
                    }
                    catch{
                        $('#no-data').css('display', 'block');
                    }
                }
            });
        });

        function getDataUsingPagination(pageNumber, regionCode){
            event.preventDefault();
            var regionCode = parseInt($('#region_code').val());       
            $('#women_list_update_spinner').css('display', 'block');
            $('#mira-women-list tbody tr').remove();
            $.ajax({
                url: '<?= base_url('/registrationhousewomenchild/getWomenListByRegionIdUsingPagination') ?>',
                data: {
                    pageNumber: pageNumber,
                    regionCode: regionCode
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    $('#women_list_update_spinner').css('display', 'none');
                    let women_data = JSON.parse(data);
                    console.log(women_data);
                    if (women_data['womenList']) {
                        $('#trdspan').css('display', 'block');
                        for (var i = 0; i < women_data['womenList'].length; i++) {
                            $("#mira-women-list tbody").append('<tr></tr>');
                            var date_string = getDateFormat(women_data['womenList'][i]['create_date']);
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + (parseInt(i) + 1) + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center"><a href="' + baseUrl + 'registrationhousewomenchild/getChildrenListByWomenId/' + women_data['womenList'][i]['women_id'] + '">' + "W" + women_data['womenList'][i]['women_id'] + '</a></td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['name'] + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + date_string + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['house_number'] + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['house_head_name'] + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['husband'] + '</td>');                    
                            if (parseInt(women_data['womenList'][i]['pregnant_status']) === 1) {
                                $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Pregnant" + '</span></td>');
                            } else {
                                $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Unpregnant" + '</span></td>');
                            }
                          
                        }
                    }
                }
            });
        }
        
        $('#btnsearch').click(function(){
            let stdate=$('#st_date_input').val();
            let endate=$('#en_date_input').val();
            let rcode=parseInt($('#region_code').val());
            let searchby=parseInt($('#searchbydate').val());
            $('#women_list_update_spinner').css('display', 'block');
            $('#mira-women-list tbody tr').remove();
            $('#pagination li').remove();
            $('#no-data').css('display', 'none');
            $.ajax({
                url: '<?= base_url('women_list_view_jqueryV2')?>',
                data: {
                    region_code: rcode,
                    start_date: stdate,
                    end_date: endate,
                    search_by: searchby,
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    $('#women_list_update_spinner').css('display', 'none');
                    $("#frd").text('0');
                    let women_data;
                    try{
                        women_data = JSON.parse(data);
                        if (women_data['womenList']) {
                            $("#frd").text(women_data['totalRecords']);
                            $('#frdspan').css('display', 'block');
                            for (var i = 0; i < women_data['womenList'].length; i++) {
                                $("#mira-women-list tbody").append('<tr></tr>');
                                var date_string = getDateFormat(women_data['womenList'][i]['create_date']);

                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + (parseInt(i) + 1) + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center"><a href="' + baseUrl + 'registrationhousewomenchild/getChildrenListByWomenId/' + women_data['womenList'][i]['women_id'] + '">' + "W" + women_data['womenList'][i]['women_id'] + '</a></td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['name'] + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + date_string + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['house_number'] + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['house_head_name'] + '</td>');
                                $('#mira-women-list tbody tr:last').append('<td class="text-center">' + women_data['womenList'][i]['husband'] + '</td>');                    
                                if (parseInt(women_data['womenList'][i]['pregnant_status']) === 1) {
                                    $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Pregnant" + '</span></td>');
                                } else {
                                    $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Unpregnant" + '</span></td>');
                                }
                            }
                        }
                        // This block is working for pagination.
                        if (women_data['totalPage'] && parseInt(women_data['totalPage']) > 1) {
                            let totalPages = parseInt(women_data['totalPage']);
                            const pagination = document.getElementById('pagination');

                            // Create previous button
                            const prevLi = document.createElement('li');
                            prevLi.className = 'page-item';
                            const prevLink = document.createElement('a');
                            prevLink.className = 'page-link';
                            prevLink.href = '#';
                            prevLink.setAttribute('aria-label', 'Previous');
                            const prevSpan = document.createElement('span');
                            prevSpan.setAttribute('aria-hidden', 'true');
                            prevSpan.innerHTML = '&laquo;';
                            prevLink.appendChild(prevSpan);
                            prevLi.appendChild(prevLink);
                            pagination.appendChild(prevLi);

                            // Create numeric page buttons using a for loop
                            for (let i = 1; i <= totalPages; i++) {
                                const pageLi = document.createElement('li');
                                pageLi.className = 'page-item';
                                const pageLink = document.createElement('a');
                                pageLink.className = 'page-link';
                                pageLink.href = '#';
                                pageLink.onclick = function() {
                                    getFilteredWomenDataUsingPagination(i, rcode, stdate, endate, searchby);
                                };
                                pageLink.textContent = i;
                                pageLi.appendChild(pageLink);
                                pagination.appendChild(pageLi);
                            }

                            // Create next button
                            const nextLi = document.createElement('li');
                            nextLi.className = 'page-item';
                            const nextLink = document.createElement('a');
                            nextLink.className = 'page-link';
                            nextLink.href = '#';
                            nextLink.setAttribute('aria-label', 'Next');
                            const nextSpan = document.createElement('span');
                            nextSpan.setAttribute('aria-hidden', 'true');
                            nextSpan.innerHTML = '&raquo;';
                            nextLink.appendChild(nextSpan);
                            nextLi.appendChild(nextLink);
                            pagination.appendChild(nextLi);
                        }
                    } 
                    catch (error) {
                        console.log("Parsing error:", error);
                        $('#no-data').css('display', 'block');
                    }
                }
            });
        });

        function getFilteredWomenDataUsingPagination(pageNumebr, regionCode, startDate, endDate, searchBy){
            event.preventDefault();
            let stdate=$('#st_date_input').val();
            let endate=$('#en_date_input').val();
            let rcode=parseInt($('#region_code').val());
            let searchby=parseInt($('#searchbydate').val());
            var _name = $('#region_code option:selected').text();           
            $('#house_list_update_spinner').css('display', 'block');
            $('#mira-women-list tbody tr').remove();
            $.ajax({
                url: '<?= base_url('/registrationhousewomenchild/getFilteredWomenDataUsingPagination')?>',
                data: {
                    page_number: pageNumebr,
                    region_code: regionCode,
                    start_date: startDate,
                    end_date: endDate,
                    search_by: searchBy
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    $('#house_list_update_spinner').css('display', 'none');
                    $('#no-data').css('display', 'none');
                    let pagination_women_data;
                    try {
                        pagination_women_data = JSON.parse(data);
                        console.log(pagination_women_data);
                        $('#frdspan').css('display', 'block');
                        for (var i = 0; i < pagination_women_data['womenList'].length; i++) {
                            $("#mira-women-list tbody").append('<tr></tr>');
                            var date_string = getDateFormat(pagination_women_data['womenList'][i]['create_date']);

                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + (parseInt(i) + 1) + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center"><a href="' + baseUrl + 'registrationhousewomenchild/getChildrenListByWomenId/' + pagination_women_data['womenList'][i]['women_id'] + '">' + "W" + pagination_women_data['womenList'][i]['women_id'] + '</a></td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + pagination_women_data['womenList'][i]['name'] + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + date_string + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + pagination_women_data['womenList'][i]['house_number'] + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + pagination_women_data['womenList'][i]['house_head_name'] + '</td>');
                            $('#mira-women-list tbody tr:last').append('<td class="text-center">' + pagination_women_data['womenList'][i]['husband'] + '</td>');                    
                            if (parseInt(pagination_women_data['womenList'][i]['pregnant_status']) === 1) {
                                $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Pregnant" + '</span></td>');
                            } else {
                                $('#mira-women-list tbody tr:last').append('<td class="text-center"><span class="label label-success">' + "Unpregnant" + '</span></td>');
                            }
                        }
                    }
                    catch (error) {
                        console.log("Parsing error:", error);
                        $('#no-data').css('display', 'block');
                    }
                }
            });
        }
        
        $('#anm_region_code').change(function () {
            var region_code = parseInt($('#anm_region_code').val());
            $('#region_code').children('option:not(:first)').remove();
            $('#region_code').css('display', 'block');

            $('#st_date_input').val('');
            $('#en_date_input').val('');
            $("#trd").text(0);
            $("#frd").text('0');
            $('#searchbydate option:first').prop('selected', true);

            $.ajax({
                url: '<?= base_url('getAshalistByANMId') ?>',
                data: {
                   region_code: region_code
                },
                type: "POST",
                success: function (json) {
                    var states = $.parseJSON(json);
                    for (var i = 0; i < states['miraList'].length; i++) {
                        $("#region_code").append($("<option></option>").val(states['miraList'][i]['region_code']).html(states['miraList'][i]['user_name']));
                    }
                    $('#asha_list_update_spinner').css('display', 'none');
                },
                error: function (xhr, status, errorThrown) {
                    $('#asha_list_update_spinner').css('display', 'none');
                },
                complete: function (xhr, status) {
                    $('#asha_list_update_spinner').css('display', 'none');
                }
            });

        });
        
        $('#st_date').datepicker({autoclose: true, format: 'dd-mm-yyyy'});
        $('#en_date').datepicker({autoclose: true, format: 'dd-mm-yyyy'});
        
    });
//    function nextDoubleClick(startingindex, regioncode, selectorid) {
//        $('#' + selectorid).append('<li class ="disabled"><span>. .. ...</span></li>');
//        $('#' + selectorid).append('<li class="page"><a href =' + '<?= base_url('women_list_view') ?>' + '/' + (startingindex + 5) + '/' + regioncode + '><span><i class="fa fa-angle-double-right" aria-hidden="true"></i><i class="fa fa-angle-double-right" aria-hidden="true"></i></span></a></li>');
//    }
//    function previousDoubleClick(startingindex, regioncode, selectorid) {
//
//        $('#' + selectorid).append('<li class="page"><a href =' + '<?= base_url('women_list_view') ?>' + '/' + (startingindex - 5) + '/' + regioncode + '><span><i class="fa fa-angle-double-left" aria-hidden="true"></i><i class="fa fa-angle-double-left" aria-hidden="true"></i></span></a></li>');
//        $('#' + selectorid).append('<li class ="disabled"><span>... .. .</span></li>');
//    }

    function previousPage(startingindex, regioncode, selectorid) {
        $('#' + selectorid).append('<li class ="disabled"><span><i class="fa fa-angle-double-left" aria-hidden="true"></i></span></li>');
    }
    function nextPage(startingindex, lastindex, regioncode, selectorid) {
        $('#' + selectorid).append('<li class="page"><a href =' + '<?= base_url('women_list_view') ?>' + '/' + (startingindex + 1) + '/' + regioncode + '><span>Next</span></a></li>');
    }
    function forLoop(startingindex, lastindex, regioncode, selectorid) {
        for (var i = 1; i <= lastindex; i++) {
            if (i === startingindex) {
                $('#' + selectorid).append('<li class="active page"><span>' + i + '</span></li>');
            } else {
                $('#' + selectorid).append('<li class="page"><a href=' + '<?= base_url('women_list_view') ?>' + '/' + i + '/' + regioncode + '><span>' + i + '</span></a></li>');
            }

        }
    }
    function getDateFormat(date) {
        var split_date_array1 = date.split('-');
        var split_date_array2 = split_date_array1[2].split(' ');
        return (split_date_array2[0] + '-' + split_date_array1[1] + '-' + split_date_array1[0]);
    }
    
    
    
    
    
</script>


