<!--custom toast-->
<div class="toast-container position-fixed bottom-0 end-0 p-3">
    <div id="liveToast" class="toast align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="d-flex">
            <div class="toast-body">
                Hello, this is a toast message!
            </div>
            <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
    </div>
</div>

<script>
    function showToast(message, type = 'primary') {
        var toastEl = document.getElementById('liveToast');
        var toastBody = toastEl.querySelector('.toast-body');

        // Ganti teks
        toastBody.innerText = message;

        // Ganti warna background sesuai tipe (success, danger, warning, info)
        toastEl.className = `toast align-items-center text-white bg-${type} border-0`;

        var toast = new bootstrap.Toast(toastEl);
        toast.show();
    }

    function showToast2(message, icon = 'success', position = 'top-end',message2 = '', bgColor = '') {
        Swal.fire({
            toast: true,
            position: position, // posisi: top-end, bottom-end, top-start, etc.
            icon: icon, // success, error, warning, info, question
            title: message,
            html: message2,
            background: bgColor,
            showConfirmButton: false,
            timer: 3000, // durasi 3 detik
            timerProgressBar: true,
            didOpen: (toast) => {
                toast.addEventListener('mouseenter', Swal.stopTimer); // biar bisa di-pause kalau mouse hover
                toast.addEventListener('mouseleave', Swal.resumeTimer); // lanjut lagi kalau mouse keluar
            }
        });
    }

</script>
// AJAX GET Request
$.ajax({
    url: url,
    type: 'GET',
    dataType: 'json', // Sesuaikan jika backend tidak mengembalikan JSON
    beforeSend: function() {
        showOverlay(); // Tampilkan overlay saat mulai
    },
    success: function (response) {
	 // cara mangil respon
	 console.log('Berhasil:', response);
        console.log('Berhasil:', response.message);
        console.log('Berhasil:', response['message']);

        showToast(response.message, 'success');
    },

    error: function (xhr, status, error) {
        console.error('Gagal:', error);
        // console.error('Gagal: bossss', status);

        showToast('Sinkronisasi Gagal', 'warning', error,'','pink','10');
        hideOverlay();
    },
    complete: function() {
        hideOverlay(); // Hilangkan overlay setelah proses selesai
    }
});

$this->db->transBegin();
// save, update
$this->db->transCommit() or die(__LINE__);

//query
$tbl = "rise_items";
$this->db = db_connect('default');
$this->db_builder = $this->db->table($tbl);
$this->db_builder->insert($dataInsert);

$existing = $this->Items_model->get_details(array('id' => $item['id']))->getRow();
$this->Items_model->ci_save($dataInsert, $item['id']); // insert dan update

//alert toast bawwan rise
appAlert.success(result.message, {duration: 10000});
info, warning, error
showToast('Sinkronisasi Gagal', 'warning', error,'','pink','10');

// untuk elemen dinamis
// $(document).on("change", "input[id^='is_multi_session_']", function () {
$(document).on("change", ".multi_session", function () {
    let userId = $(this).data("id");
    let isChecked = $(this).is(":checked") ? 1 : 0;

}

// untuk elemen yg sudah pasti ada di DOM
$('.multi_session').on("change", function () { ... })

//pasang log di controller
// $is_mode: cocok diisi bila hanya update 1kolom doang
$this->Users_model->init_activity_log("roles", "email",$is_mode);

/** ----------------------------------------------------
 * untuk menyembunyikan user ghost yg bisa lihat hanya admin
 * ----------------------------------------------------*/
if (!$this->login_user->is_admin) {
    $options["non_gost_users_only"] = true;
}