<div class="col-12">
{*
    <div class="col-12">
        <button class="btn btn-dark mb-0" onclick="smallModal('createBannedWord')">{$lang.datatable.add_banned_word}</button>
    </div>*}
    {include file='main/datatable.tpl' tableTitle="{$lang.nav.punishmentlogs}"
    theads=[{$lang.datatable.uniq_id}, {$lang.datatable.ip_address}, {$lang.datatable.email }, {$lang.datatable.comment}, {$lang.datatable.banned_word}, {$lang.datatable.status}, {$lang.datatable.actions}]
    data=$punishmentLogs }

</div>

<div id="banUser" class="hidden">
    <h5 class="mt-0">{$lang.datatable.ban_user_comment}:</h5>
    <form method="POST">
        <input type="hidden" name="form_key" value="{$form_key}">
        <input type="hidden" id="pl_id" name="pl_id" value="">
        <div class="row">
            <div class="col-6">
                <label class="col-form-label mt-1">Время блокировки</label>
                <select class="form-select" name="punishment_type" required>
                    <option value="" disabled selected>- Выберите вермя блокировки -</option>
                    {foreach from=$punishmentTypes item=punishmentType}
                        <option value="{$punishmentType.id}">{$punishmentType.name}</option>
                    {/foreach}
                </select>
            </div>
            <div class="col-12">
                <button type="submit" name="ban_user" class="btn btn-success mt-4" id="submitButton">{$lang.datatable.ban}</button>
            </div>
        </div>
    </form>
</div>



<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
    $(document).ready(function() {
        $(".ban-user").on("click", function () {
            smallModal('banUser');

            let plId = $(this).attr("data-id");
            const editBannedWordModal = $("#banUser");

            editBannedWordModal.find("#pl_id").val(plId);

        });


        $(".unban-user").on("click", function () {
            let plId = $(this).attr("data-id");


            Swal.fire({
                title: 'Подтверждение',
                text: 'Вы уверены что хотите разблокировать раньше времени?',
                icon: 'question',
                showCancelButton: true,
                confirmButtonText: 'Да',
                cancelButtonText: 'Нет'
            }).then((result) => {
                if (result.isConfirmed) {
                    $.ajax({
                        url: '/engine/ajax/lib/punishments/unlock.php',
                        type: 'POST',
                        data: { id: plId },
                        success: function (response) {
                            Swal.fire('Успех!', 'Разблокировано.', 'success').then(() => {
                                location.reload();
                            });
                        },
                        error: function () {
                            Swal.fire('Ошибка!', 'Что-то пошло не так.', 'error');
                        }
                    });
                } else if (result.dismiss === Swal.DismissReason.cancel) {

                }
            });

        })

        var wabSection = document.getElementById('oaaSection');
        wabSection.classList.add('active');
        var widgetsAndBanners = document.getElementById('ordersAndApplications');
        widgetsAndBanners.classList.add('show');

        $("#punishmentLogs").addClass("active");

    });
</script>