<style>
    .form-group input[type="checkbox"] {
        display: none;
    }

    .form-group input[type="checkbox"] + .btn-group > label span {
        width: 20px;
    }

    .form-group input[type="checkbox"] + .btn-group > label span:first-child {
        display: none;
    }
    .form-group input[type="checkbox"] + .btn-group > label span:last-child {
        display: inline-block;   
    }

    .form-group input[type="checkbox"]:checked + .btn-group > label span:first-child {
        display: inline-block;
    }
    .form-group input[type="checkbox"]:checked + .btn-group > label span:last-child {
        display: none;   
    }
    #mira-application-region{
        border: 2px solid #dddddd;
    }
    #mira-application-region > thead > tr > th,
    #mira-application-region > tbody > tr > th,
    #mira-application-region > tfoot > tr > th,
    #mira-application-region > thead > tr > td,
    #mira-application-region > tbody > tr > td,
    #mira-application-region > tfoot > tr > td {
        border: 2px solid #dddddd;

    }
    #mira-application-region{
        width: 100%;
        overflow-x: scroll;
    }



    #mira-user-detail{
        border: 2px solid #dddddd;
    }
    #mira-user-detail > thead > tr > th,
    #mira-user-detail > tbody > tr > th,
    #mira-user-detail > tfoot > tr > th,
    #mira-user-detail > thead > tr > td,
    #mira-user-detail > tbody > tr > td,
    #mira-user-detail > tfoot > tr > td {
        border: 2px solid #dddddd;

    }
    #mira-user-detail{
        width: 100%;
        overflow-x: scroll;
    }


    #admin-user-right{
        border: 2px solid #dddddd;
    }
    #admin-user-right > thead > tr > th,
    #admin-user-right > tbody > tr > th,
    #admin-user-right > tfoot > tr > th,
    #admin-user-right > thead > tr > td,
    #admin-user-right > tbody > tr > td,
    #admin-user-right > tfoot > tr > td {
        border: 2px solid #dddddd;

    }
    #admin-user-right{
        width: 100%;
        overflow-x: scroll;
    }

</style>
<div class="panel"> 
    <div class="panel-body">

        <h2 class="text-center">Mapped Region To User List</h2>  
        <hr class="colorgraph">

        <div class="panel">
            <div class="panel-body">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row" >
                            <div class="col-md-6 col-md-push-3">
                                <div class="form-group">
                                    <div class="input-group">
                                        <span class="input-group-addon"><i aria-hidden="true"></i>Select Region Level</span>
                                        <select id="region_level" name="region_level" required class="form-control">
                                            <option value="0" disabled="true" selected> Select Region Level</option>
                                            <?php if (isset($level) and $level) {
                                                for ($i = 0; $i < count($level); $i++) {
                                                    ?>
                                                    <option value=<?= $level[$i]['hierar_level_id'] ?>> <?= $level[$i]['hierar_level_name'] ?></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-md-1 col-md-push-3 spinner" id="region_level_spinner" style="display: none;margin-top: 5px">
                                <i class="fa fa-spinner fa-spin"></i>
                            </div>
                        </div>        
                    </div>
                </div>
                <table id="mira-application-region" class="table table-bordred table-striped">
                    <thead>
                        <tr>
                            <th colspan="6"><h4 class="text-center"> <strong>Region Detail</strong></h4></th>
                    </tr>
                    <tr>
                        <th class="text-center">Region Name</th>
                        <th class="text-center">User Name</th>
                        <th class="text-center">Mapped Date</th>
                        <th class="text-center">Level</th>
                        <th class="text-center">Phone</th>
                        <th class="text-center">Activation Status</th>
                    </tr>
                    </thead>
                    <tbody>


                    </tbody>
                </table>


            </div>
        </div>

        <hr class="colorgraph">

    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#region_level').change(function () {
            $('#region_level_spinner').css('display', 'block');

            $("#mira-application-region tbody tr").remove();

            $.ajax({
                url: '<?= base_url('mapped_list') ?>',
                data: {
                    region_level: $('#region_level').val()
                },
                type: "POST",
                success: function (json) {
                    var data = $.parseJSON(json);
                    if (data['mapped_list']) {
                        for (var i = 0; i < data['mapped_list'].length; i++) {
                            $("#mira-application-region tbody").append('<tr></tr>');
                            if (data['mapped_list'][i]['activate_date'] == null) {
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-info'>" + data['mapped_list'][i]['region_name'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-info'>" + data['mapped_list'][i]['user_name'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-info'>" + data['mapped_list'][i]['mapping_date'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-info'>" + data['mapped_list'][i]['user_level'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-info'>" + data['mapped_list'][i]['mobile'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-info'><span class='label label-danger'>Activation Pending..</span></td>");

                            } else {
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-success'>" + data['mapped_list'][i]['region_name'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-success'>" + data['mapped_list'][i]['user_name'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-success'>" + data['mapped_list'][i]['mapping_date'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-success'>" + data['mapped_list'][i]['user_level'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-success'>" + data['mapped_list'][i]['mobile'] + "</td>");
                                $("#mira-application-region tbody tr:last").append("<td class='text-center text-info'><span class='label label-success'>Activated</span></td>");

                            }


                        }
                    }


                },
                error: function (xhr, status, errorThrown) {
                    $('#region_level_spinner').css('display', 'none');
                },
                complete: function (xhr, status) {
                    $('#region_level_spinner').css('display', 'none');
                }
            });
        });
    });
</script>
