<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" />
<!-- Begin Page Content -->
<style>
video {
    width: 100%
}

table {
    width: 100%;
    border-collapse: collapse;
}

td,
th {
    padding: 8px;
    text-align: left;
}

.fw-bold {
    font-weight: 700;
    color: #000;

}

@media (max-width: 768px) {

    /* Change table layout to block on small screens */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    /* Hide the table headers */
    thead tr {
        display: none;
    }

    /* Display each row as a card */
    tr {
        margin-bottom: 8px;
        border-bottom: 2px solid #bbb;
    }

    /* Label each cell for clarity */
    .sort-button {
        font-size: 12px;
        cursor: pointer;
        margin-left: 5px;

    }
}
</style>
<div class="container-fluid">
    <div class="row column_title">
        <div class="col-md-12">
            <div class="page_title">
                <h2>Suspension History</h2>
            </div>
        </div>
    </div>


    <div class="card shadow mb-4">
        <div class="card-body">
            <!-- <button type="button" style="float: right" onclick="location.href='<?= base_url() . 'dashboard/addmeditation' ?>'" class="btn btn-primary mb-5">Add Session</button> -->
            <div class="table-responsive">
                <table class="table table-striped" id="songTable">
                    <thead class="thead-dark">
                        <tr>
                            <th>Reason</th>
                            <th>Suspension Date</th>
                            <th>Reactivation Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Misuse of platform</td>
                            <td>19 April, 2025</td>
                            <td>25 April, 2025</td>
                        </tr>
                        <tr>
                            <td>Violation of TOS</td>
                            <td>11 January, 2025</td>
                            <td>01 March, 2025</td>
                        </tr>


                        <?php
                        if (!empty($meditations)) {
                            foreach ($meditations as $id => $meditation) {
                        ?>
                        <tr>

                            <td class="">
                                <?=$meditation['sessionNo']?>
                            </td>
                            <td class="">
                                <?=$meditation['title']?>
                            </td>
                            <td class="">
                                <?=$meditation['congratsMessage']?>
                            </td>
                            <!-- <td class="">
                                <img class="img-fluid" src="<?=$meditation['image']?>" width="150" height="150" />
                            </td> -->
                            <td class="">
                                <!-- <label class="form-label">Speaker1</label> -->
                                <audio controls>
                                    <source src="<?=$meditation['audio1']?>">
                                    Your browser does not support the audio element.
                                </audio>
                                <br><br>
                                <audio controls>
                                    <source src="<?=$meditation['audio2']?>">
                                    Your browser does not support the audio element.
                                </audio>
                                <br><br>
                                <audio controls>
                                    <source src="<?=$meditation['audio3']?>">
                                    Your browser does not support the audio element.
                                </audio>
                            </td>
                            <td class="">
                                <?=$meditation['regularXP']?>
                            </td>
                            <td class="">
                                <?=$meditation['relistenXP']?>
                            </td>

                            <td>
                                <a class="icon" style="text-decoration: none;" href="<?php echo base_url(); ?>dashboard/addmeditation/<?php echo output($id); ?>">
                                    <button class="btn btn-info btn-block mt-2">Edit</button>
                                </a>
                                <button class="btn btn-danger btn-block mt-2" data-toggle="modal" data-target="#exampleModa2" onclick="showConfirmation('<?=$id?>', '<?=$music['title']?>', 'deleteMeditation');">Delete</button>
                            </td>
                        </tr>

                        <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>

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

</div>
<!-- /.container-fluid -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <form method="post" action="<?= base_url('customer/suspend') ?>">
        <input id="userId" type="hidden" name="userId" value="" />
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 id="exampleModalLabel">Suspend restaurant "<span id="user-name">"</span>
                    </h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="message-text" class="col-form-label">Reason:</label>
                        <input type="text" class="form-control" id="reason" name="reason" required>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal">Suspend</button>
                    <!-- <button type="submit" class="btn btn-primary">Suspend</button> -->
                </div>
            </div>
        </div>
    </form>
</div>
<div class="modal fade" id="exampleModa2" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <form method="get" name="cform" action="">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel2"></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary" id="submitBtn"></button>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
function suspend(userid, username) {
    console.log(userid, username)
    document.getElementById('user-name').innerText = username;
    document.getElementById('userId').value = userid;
}

function showConfirmation(userid, username, action) {
    console.log(userid, username, action);
    let url = "";
    let message = "";
    let btnTitle = "";
    switch (action) {
        case 'deleteMeditation':
            url = "<?php echo base_url(); ?>dashboard/deleteMeditation/" + userid;
            message = "Are you sure you want to delete meditation '" + username + "'?";
            btnTitle = "Delete Meditation";
            break;
        case 'deleteImage':
            url = "<?php echo base_url(); ?>customer/deleteImage/" + userid;
            message = "Are you sure you want to remove profile phot of user '" + username + "'?";
            btnTitle = "Remove Profile Photo";
            break;
        case 'banCustomer':
            url = "<?php echo base_url(); ?>customer/banCustomer/" + userid;
            message = "Are you sure you want to ban user '" + username + "'?";
            btnTitle = "Ban User";
            break;
        case 'unBanCustomer':
            url = "<?php echo base_url(); ?>customer/unBanCustomer/" + userid;
            message = "Are you sure you want to Unbanned user '" + username + "'?";
            btnTitle = "Unban User";
            break;
        case 'suspendCustomer':
            url = "<?php echo base_url(); ?>customer/suspendCustomer/" + userid;
            message = "Are you sure you want to deactivate user '" + username + "'?";
            btnTitle = "Deactivate User";
            break;
        case 'unSuspendCustomer':
            url = "<?php echo base_url(); ?>customer/unSuspendCustomer/" + userid;
            message = "Are you sure you want to activate user '" + username + "'?";
            btnTitle = "Activate User";
            break;
        case 'deleteCustomer':
            url = "<?php echo base_url(); ?>customer/remove/" + userid + "/user";
            message = "Are you sure you want to delete user '" + username + "'?";
            btnTitle = "Delete User";
            break;
        default:
            return false;
    }

    document.getElementById('exampleModalLabel2').innerText = message;
    document.getElementById('submitBtn').innerText = btnTitle;
    document.cform.action = url;
}


$(document).ready(function() {
    $('#songTable').DataTable();
});

// Custom sorting function
function sortTable(columnIndex) {
    var table = $('#songTable').DataTable();
    var currentOrder = table.order();

    // Toggle sorting order based on current state
    if (currentOrder[0][0] === columnIndex) {
        // Reverse the order if already sorted on this column
        var newOrder = currentOrder[0][1] === 'asc' ? 'desc' : 'asc';
        table.order([columnIndex, newOrder]).draw();
    } else {
        // Sort in ascending order if sorting for the first time
        table.order([columnIndex, 'asc']).draw();
    }
}
</script>