<?php include'header.php'; ?>	

<div class="app-content content">
    <div class="content-overlay"></div>
    <div class="content-wrapper">
        <div class="content-header row"></div>
        <div class="content-body"> 

                <div class="row">
                    <div class="col-12">
                        <div class="card">

                            <div class="card-header">
                                <h4 class="card-title mb-1">state</h4>
                            </div>

                            <div class="card-content">
                                <div class="card-body">



<!-- CUSTOMER LIST TABLE -->
<div class="table-responsive col-md-12 s-right mt-2">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>name</th>
                <th>status</th>
                
            </tr>
        </thead>

        <tbody>
<?php
$obj->sql("SELECT * FROM state ORDER BY id ASC");
$result = $obj->getResult();
foreach ($result as $row) { ?>
    <tr>
        <td><?php echo $row['name']; ?></td>
        <td>
            <div class="custom-control custom-switch custom-switch-success">
                <input type="checkbox" class="custom-control-input  status-toggle" data-id="<?php echo $row['id']; ?>" id="customSwitch<?php echo $row['id']; ?>" <?php if($row['status'] == 1){ echo 'checked'; } ?> >
                <label class="custom-control-label" for="customSwitch<?php echo $row['id']; ?>"></label>
            </div>        
        </td>        
    </tr>
<?php } ?>

        </tbody>
    </table>
</div>


                        </div><!-- card-content -->
                    </div><!-- card -->
                </div>
            </div>
        </section>

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

<div class="sidenav-overlay"></div>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$('.status-toggle').change(function(){
    var status = $(this).prop('checked') == true ? 1 : 0;
    var id = $(this).data('id');
    $.ajax({
        url : 'ajax/update-state-status.php',
        type : 'POST',
        data : {
            id : id,
            status : status
        },
        success:function(response){
            console.log(response);
        }
    });
});
</script>
<?php include'footer.php'; ?>
