<!DOCTYPE html>
<html lang="id">
<!--begin::Head-->

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <!-- Default values (akan diubah JS) -->
    <title>Loading...</title>
    <meta name="description" content="Memuat data toko..." />

    <!-- Favicon default -->
    <link id="dynamic-favicon" rel="icon" href="icons/logo_placeholder.png" type="image/png" />

    <!-- OG Meta default -->
    <meta property="og:title" content="Loading..." />
    <meta property="og:description" content="Memuat data toko..." />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="" />
    <meta property="og:image" content="icons/logo_placeholder.png" />
    <meta property="og:site_name" content="Aplikasi Toko" />

    <!-- Twitter Meta -->
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:title" content="Loading..." />
    <meta name="twitter:description" content="Memuat data toko..." />
    <meta name="twitter:image" content="icons/logo_placeholder.png" />

    <?php include_once("assets/addon/icon_css.php"); ?>
</head>
<!--end::Head-->
<!--begin::Custom Style-->
<style>
    .hover-elevate:hover {
        transform: translateY(-3px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
        transition: all 0.2s ease-in-out;
    }
</style>
<!--end::Custom Style-->
<!--begin::Body-->

<body id="kt_body" class="header-extended header-fixed header-tablet-and-mobile-fixed">

    <!--begin::Main-->
    <!--begin::Root-->
    <div class="d-flex flex-column flex-root">
        <!--begin::Page-->
        <div class="page d-flex flex-row flex-column-fluid">
            <!--begin::Wrapper-->
            <div class="wrapper d-flex flex-column flex-row-fluid" id="kt_wrapper">
                <!--begin::Header-->
                <?php include_once("assets/addon/header.php"); ?>
                <!--end::Header-->




                <!--begin::Container-->
                <div id="kt_content_container" class="d-flex flex-column-fluid align-items-start container-xxl">
                    <!--begin::Post-->
                    <div class="content flex-row-fluid" id="kt_content">

                        <!--begin::Breadcrumb-->
                        <div id="breadcrumb_container"></div>
                        <!--end::Breadcrumb-->

                        <!--begin::Row - Menu Shortcut-->
                        <div class="row g-5">

                            <div class="d-flex justify-content-between align-items-center mb-3">
                                <h4 class="fw-bold mb-0">Daftar Player</h4>
                            </div>

                            <div class="col-12">

                                <div class="card shadow-sm border-0">
                                    <div class="card-body py-5">



                                        <div id="data_table"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--end::Row - Menu Shortcut-->

                    </div>
                    <!--end::Post-->
                </div>
                <!--end::Container-->

                <!--begin::Footer-->
                <?php include_once("assets/addon/footer.php"); ?>
                <!--end::Footer-->

            </div>
            <!--end::Wrapper-->
        </div>
        <!--end::Page-->


    </div>
    <!--end::Root-->

    <!--end::Main-->


    <!--begin::Javascript-->
    <!--begin::Global Javascript Bundle(mandatory for all pages)-->
    <?php include_once 'assets/addon/scripts.php'; ?>
    <?php
    $active_namespaces = ['login', 'header', 'generic'];
    include_once 'locales/init.php';
    ?>

    <!--begin::Global Javascript Bundle(mandatory for all pages)-->
    <!--end::Global Javascript Bundle-->

    <!--begin::Vendors Javascript(used for this page only)-->
    <script src="assets/plugins/custom/datatables/datatables.bundle.js"></script>
    <!--end::Vendors Javascript-->

    <!--begin::Custom Javascript(used for this page only)-->
    <script type="module">
        import { checkSession, toggleContentOverlay, updateHeaderUser } from './modules/session.js';
        import { getActiveUser } from './col_script/essential/user_helper.js';
        import { setLocales_textContent, initDynamicLanguageHandler } from './col_script/common/locales_helper.js';
        import { q_setVisibility, q_setText, q_isValidDatetime, q_setDateTimeToFormat, q_updateMetaData, q_generateListErrorMessage } from './col_script/common/qol.js';
        import { fetch_helper } from "./col_script/common/fetch_helper.js";
        import { getDeviceInfo, getSafeLocalStorageItem, setSafeLocalStorageItem, removeSafeLocalStorageItem } from './col_script/common/device_info.js';
        import { generateDatatableHTML } from "./col_script/common/datatable_html.js";
        import { initDatatable } from "./col_script/common/datatable_helper.js";
        import { setBreadcrumb } from "./col_script/common/router_helper.js";
        import DataTable from './modules/DataTable.js';
        import PopupDialogSearch from './modules/PopupDialogSearch.js';

        const alert_nolink = document.getElementById("alert_nolink");

        const listRankCategory = [];
        let rankCategoryPopup = null;

        // 🧩 Kumpulan semua elemen dashboard
        const elDashboard = {

        };



        async function load(listU, listA) {

            let AksesNeeded = "Player.View";
            const aksesNames = listA.map(a => a.AksesName);
            if (!aksesNames.includes(AksesNeeded)) {
                showUnauthorizedAlert(AksesNeeded);
                return;
            }

            setBreadcrumb("#breadcrumb_container", ["Dashboard", "Player"]);

            const formData = new URLSearchParams();
            formData.append("p_type", "launcher");
            formData.append("p_action", "select");

            formData.append("getPerusahaan", "1");

            formData.append("getRankingCategory", "1");
            formData.append("getRankingCategory_IsActive", "1");

            const { result } = await fetch_helper({
                i18nKey: "", // ganti jika key i18next-nya berbeda
                fetchFile: "",
                formData: formData,
            });


            if (result.Status == 1) {

                if (result.listPerusahaan && result.listPerusahaan.length > 0) {
                    const items = result.listPerusahaan;
                    items.forEach((item) => {

                        let URL_BASE = "attachments/perusahaan";
                        const nama = item.NamaPerusahaan || "Perusahaan Tanpa Nama";
                        const deskripsi = "Player";
                        const logo = item.Logo ? `${URL_BASE}/${item.Logo}` : "icons/logo_palceholder.png";

                        const elLogo = document.querySelector('[data-header-element="logo"]');
                        if (elLogo) {
                            elLogo.src = logo; // ganti path logo di sini
                        }

                        q_updateMetaData({
                            title: `${deskripsi} – ${nama}`,
                            description: deskripsi,
                            image: logo,
                            favicon: logo,
                            url: window.location.href,
                        });

                    });
                }

                if (result.listRankingCategory && result.listRankingCategory.length > 0) {
                    listRankCategory.push(...result.listRankingCategory);
                }

                // Buat/inisialisasi popup rank category
                initRankCategoryPopupForBatch();
                initDt();
            } else {
                Swal.fire({
                    text: i18next.t(result.Keterangan),
                    icon: "error",
                    buttonsStyling: false,
                    confirmButtonText: "Ok, got it!",
                    customClass: { confirmButton: "btn btn-primary" },
                });
            }
        }

        async function initDt() {
            // === Konfigurasi Display Columns ===
            const displayColumns = [
                //{ columnName: "IDPlayer", displayedName: "ID", isShown: false },
                { columnName: "IDPlayer", displayedName: "ID", isShown: true, dataType: "numeric" },
                { columnName: "full_name", displayedName: "Nama Lengkap", dataType: "text" }, 
                { columnName: "email", displayedName: "Email", dataType: "text" },
                { columnName: "CategoryName", displayedName: "Rank", dataType: "text" },
                { columnName: "CategoryCode", displayedName: "Rank Code", dataType: "text" },
                { columnName: "gender", displayedName: "Gender", dataType: "enum", enumFormat: (val) => val || '-' },
                {
                    columnName: "photo",
                    displayedName: "Foto Profil",
                    dataType: "image",
                    imageParameter: {
                        type: 'circle',
                        height: 40,
                        width: 40,
                        urlPath: '../api/assets/player',  // Base path
                        subPathColumn: 'IDPlayer',
                        canZoom: true
                    }
                },
                { columnName: "MembershipNumber", displayedName: "Membership Number", dataType: "text" },
                { columnName: "TanggalExpired", displayedName: "Tanggal Expired", dataType: "datetime", dateFormat: "dd-MM-yyyy" },
                {
                    columnName: "StatusMembership",
                    displayedName: "Status Membership",
                    dataType: "enum",
                    enumFormat: (val) => {
                        const map = {
                            'Active': '<span class="badge bg-success text-light">Active</span>',
                            'Inactive': '<span class="badge bg-danger text-light">Inactive</span>',
                            'Expired': '<span class="badge bg-warning ">Expired</span>',
                            'Expiring Soon': '<span class="badge bg-info">Expiring Soon</span>',
                            'No Membership': '<span class="badge bg-secondary">No Membership</span>',
                        };
                        return map[val] || val || '-';
                    }
                },
                { columnName: "TanggalBayar", displayedName: "Tanggal Bayar", dataType: "datetime", dateFormat: "dd-MM-yyyy" },
                {
                    columnName: "PaymentStatus",
                    displayedName: "Status Payment",
                    dataType: "enum",
                    enumFormat: (val) => {
                        const map = {
                            'approved': '<span class="badge bg-success text-light">Approved</span>',
                            'waiting': '<span class="badge bg-warning">Waiting</span>',
                            'rejected': '<span class="badge bg-danger text-light">Rejected</span>',
                        };
                        return map[val] || val || '-';
                    }
                },
                { columnName: "ranking_position", displayedName: "Ranking", dataType: "numeric" },
                { columnName: "total_points", displayedName: "Total Poin", dataType: "numeric" },
                { columnName: "CreateBy", dataType: "text" },
                { columnName: "CreateAt", dataType: "datetime", dateFormat: "dd-MM-yyyy HH:mm:ss" },
                { columnName: "LastUpdateBy", dataType: "text" },
                { columnName: "LastUpdateAt", dataType: "datetime", dateFormat: "dd-MM-yyyy HH:mm:ss" },
            ];

            // === Konfigurasi Filter ===
            const filterConfigs = [
                {
                    key: "StatusMembership",
                    label: "Status Membership",
                    type: "options",
                    options: [
                        { display: "Semua", value: "" },
                        { display: "Active", value: "active" },
                        { display: "Inactive", value: "inactive" },
                        { display: "Expired", value: "expired" }
                    ]
                },
                {
                    key: "PaymentStatus",
                    label: "Status Payment",
                    type: "options",
                    options: [
                        { display: "Semua", value: "" },
                        { display: "Waiting", value: "waiting" },
                        { display: "Approved", value: "approved" },
                        { display: "Rejected", value: "rejected" },
                    ]
                },
                {
                    key: "gender",
                    label: "Gender",
                    type: "options",
                    options: [
                        { display: "Semua", value: "" },
                        { display: "Male", value: "male" },
                        { display: "Female", value: "female" },
                    ]
                },
                {
                    key: "IDRankCategory",
                    label: "Rank Category",
                    type: "options",
                    options: [
                        { display: "Semua", value: "" },
                        ...listRankCategory.map(item => ({
                            display: `${item.CategoryName} (${item.CategoryCode})`,
                            value: item.IDRankCategory
                        }))
                    ]
                }
            ];

            // === Action Buttons ===
            const actionButtons = [
                {
                    buttonType: 'View',
                    actionType: 'Redirect',
                    URLPath: 'm_player_add.php',
                    ColumnSendForURL: [
                        { columnName: 'IDPlayer', paramName: 'id' }, // kirim IDPlayer sebagai ?id=xxx
                    ],
                    label: 'Detail'
                },
                /* {
                     buttonType: 'Edit',
                     actionType: 'Redirect',
                     URLPath: 'm_player_add.php',
                     ColumnSendForURL: [
                         { columnName: 'IDPlayer', paramName: 'id' }, // kirim IDPlayer sebagai ?id=xxx
                     ],
                     label: 'Edit'
                 },*/
                {
                    key: 'delete',
                    buttonType: 'Delete',
                    actionType: 'Callback',
                    callbackFunction: async (row) => {
                        console.log("Delete callback for row:", row);
                        const result = await Swal.fire({
                            text: `Yakin ingin menghapus data ${row.full_name || row.email}?`,
                            icon: 'warning',
                            showCancelButton: true,
                            confirmButtonText: 'Ya, Hapus',
                            cancelButtonText: 'Batal',
                        });

                        if (result.isConfirmed) {
                            const formData = new URLSearchParams();
                            formData.append("p_type", "player");
                            formData.append("p_action", "delete");
                            formData.append("IDPlayer", row.IDPlayer);

                            const { result: deleteResult } = await fetch_helper({
                                formData: formData,
                            });

                            await q_generateListErrorMessage(deleteResult, [
                                { display: "Nama Player", value: "NamaPlayer" },
                                { display: "Keterangan", value: "Keterangan" },
                            ]);

                            if (deleteResult.Status === 1) {
                                dtInstance.loadData();
                            }
                        }
                    }
                }
            ];

            // === Bulk Actions ===
            const bulkActions = [
                {
                    key: 'delete_multiple',
                    label: 'Hapus Terpilih',
                    icon: 'fa-trash',
                    confirm: 'Yakin ingin menghapus data terpilih?',
                    callback: async (selectedData, selectedIds) => {
                        const formData = new URLSearchParams();
                        formData.append("p_type", "player");
                        formData.append("p_action", "delete");
                        //formData.append("IDPlayer", JSON.stringify(selectedIds));
                        formData.append("IDPlayer", selectedIds.join(','));

                        const { result: deleteResult } = await fetch_helper({ formData });

                        await q_generateListErrorMessage(deleteResult, [
                            { display: "Nama Player", value: "NamaPlayer" },
                            { display: "Keterangan", value: "Keterangan" },
                        ]);

                        if (deleteResult.Status === 1) {
                            dtInstance.loadData();
                        }
                    }
                },

                {
                    key: 'set_rank_batch',
                    label: 'Set Rank Batch',
                    icon: 'fa-edit',
                    confirm: 'Yakin ingin mengatur rank untuk data terpilih?',
                    callback: async (selectedData, selectedIds) => {


                        // Simpan selectedIds ke variable global untuk digunakan di onPick
                        window._batchSelectedIds = selectedIds;



                        // Buka popup dengan onPick override
                        if (rankCategoryPopup) {
                            rankCategoryPopup.openManually({
                                onPickOverride: async (row) => {
                                    try {
                                        const formData = new URLSearchParams();
                                        formData.append('p_type', 'player');
                                        formData.append('p_action', 'set_rank');
                                        formData.append('IDPlayer', window._batchSelectedIds.join(','));
                                        formData.append('IDRankCategory', row.IDRankCategory);
                                        formData.append('PromotionReason', `Batch set rank to ${row.CategoryName} (${row.CategoryCode})`);
                                        formData.append('IsManualOverride', '1');

                                        const { result } = await fetch_helper({ formData });

                                        if (result.Status === 1) {
                                            Swal.fire({
                                                text: result.Keterangan,
                                                icon: 'success',
                                                buttonsStyling: false,
                                                confirmButtonText: 'OK',
                                                customClass: { confirmButton: 'btn btn-primary' },
                                            }).then(() => {
                                                if (dtInstance) {
                                                    dtInstance.loadData();
                                                }
                                            });
                                        } else {
                                            throw new Error(result.Keterangan);
                                        }
                                    } catch (error) {
                                        Swal.fire({
                                            text: error.message,
                                            icon: 'error',
                                            buttonsStyling: false,
                                            confirmButtonText: 'OK',
                                            customClass: { confirmButton: 'btn btn-primary' },
                                        });
                                    } finally {
                                        // Cleanup
                                        window._batchSelectedIds = null;
                                    }
                                }
                            });
                        }
                    }
                }
            ];

            // === Inisialisasi DataTable ===
            const formData = new URLSearchParams();
            formData.append("p_type", "player");
            formData.append("p_action", "select_general");

            const dtInstance = new DataTable({
                containerId: 'data_table',
                formData: formData,
                displayColumns: displayColumns,
                filterConfigs: filterConfigs,
                actionButtons: actionButtons,
                bulkActions: bulkActions,
                orderColumnList: [
                    { display: 'Nama Lengkap', columnName: 'full_name' },
                    { display: 'Email', columnName: 'email' },
                    { display: 'Status Membership', columnName: 'StatusMembership' },
                    { display: 'Status', columnName: 'PlayerStatusAktif' },
                    { display: 'Ranking', columnName: 'ranking_position' },
                    { display: 'Total Poin', columnName: 'total_points' },
                ],
                rowSelection: {
                    enabled: true,
                    rowKey: 'IDPlayer',
                },
                fetchHelper: fetch_helper,
                onAddNew: () => {
                    window.location.href = 'm_player_add.php';
                },
                addNewLabel: 'Tambah Player',
                defaultRowsPerPage: 25,
                rowsPerPageOptions: [10, 25, 50, 100, 250, 500],
                // Optional: bisa override default
                // defaultOrderColumn: { display: 'ID Terbaru', columnName: 'IDPlayer' },
                // defaultOrderDirection: 'DESC',
                exportOptions: {
                    copy: true,
                    csv: true,
                    excel: true,
                    pdf: false,
                },
                allowFilter: true,
                allowOrder: true,
                allowPaging: true,
                allowExport: true,
            });

            // === Render dan Load Data ===
            dtInstance.render();

            // Action dari row
            document.addEventListener('datatable:action', (e) => {
                const { action, rowId } = e.detail;
                console.log(`Action ${action} on row ${rowId}`);
                // Bisa ditangani di sini jika diperlukan
            });

        }

        // Inisialisasi popup untuk batch
        function initRankCategoryPopupForBatch() {
            // Hanya inisialisasi sekali
            if (rankCategoryPopup) {
                return;
            }

            // Buat container untuk popup
            let container = document.getElementById('rankCategoryPopupContainer');
            if (!container) {
                container = document.createElement('div');
                container.id = 'rankCategoryPopupContainer';
                document.body.appendChild(container);
            }

            // Konfigurasi untuk PopupDialogSearch (Rank Category)
            const rankCategoryConfig = {
                containerId: 'rankCategoryPopupContainer',
                title: 'Pilih Rank Category untuk Batch',
                columns: [
                    { columnName: 'IDRankCategory', displayedName: 'ID' },
                    { columnName: 'CategoryCode', displayedName: 'Kode' },
                    { columnName: 'CategoryName', displayedName: 'Nama Kategori' },
                    { columnName: 'MinPoints', displayedName: 'Min Points' },
                    { columnName: 'MaxPoints', displayedName: 'Max Points' },
                    { columnName: 'IsDefaultRank', displayedName: 'Default' },
                    { columnName: 'IsActive', displayedName: 'Status' },
                ],
                filterConfigs: [
                    {
                        key: "IsActive",
                        label: "Status",
                        type: "options",
                        options: [
                            { display: "Semua", value: "" },
                            { display: "Aktif", value: "1" },
                            { display: "Non Aktif", value: "0" }
                        ]
                    }
                ],
                fetchData: async (params) => {
                    const formData = new URLSearchParams();
                    formData.append('p_type', 'ranking_category');
                    formData.append('p_action', 'select');
                    formData.append('search', params.search);
                    formData.append('page_number', params.page);
                    formData.append('rows_per_page', params.rowsPerPage);

                    if (params.filters && Array.isArray(params.filters)) {
                        const validFilters = params.filters.filter(f =>
                            Array.isArray(f) && f.length === 3 && typeof f[0] === 'string'
                        );
                        if (validFilters.length > 0) {
                            formData.append('filters', JSON.stringify(validFilters));
                        }
                    }

                    const { result } = await fetch_helper({ formData });
                    return {
                        data: result.list_data || [],
                        totalData: result.total_rows || 0,
                        totalPage: result.total_page || 1,
                    };
                },
                additionalElements: [],
                rowsPerPage: 25,
                rowsPerPageOptions: [5, 10, 25, 50, 100],
                // onPick akan di-override saat dipanggil
            };

            rankCategoryPopup = new PopupDialogSearch(rankCategoryConfig);
            rankCategoryPopup.init();
        }

        async function initDt_old() {
            const formData = new URLSearchParams();
            formData.append("p_type", "player");
            formData.append("p_action", "select_general");

            const allowAction = true;

            const filterKolom = [
                ["StatusMembership", "Filter Status Membership", "options", [
                    { display: "Semua", value: "" },
                    { display: "Active", value: "active" },
                    { display: "Inactive", value: "inactive" },
                ]],

                ["PaymentStatus", "Filter Status Payment", "options", [
                    { display: "Semua", value: "" },
                    { display: "Waiting", value: "waiting" },
                    { display: "Approved", value: "approved" },
                    { display: "Rejected", value: "rejected" },
                ]],
            ];


            const { tableId } = generateDatatableHTML({
                targetSelector: "#data_table",
                allowAction: allowAction,
                filters: filterKolom
            });

            const delete_action_callback = async (ids) => {
                console.log("Delete callback:", ids);

                const formData = new URLSearchParams();
                formData.append("p_type", "player");
                formData.append("p_action", "delete");
                formData.append("IDPlayer", ids);

                const { result } = await fetch_helper({
                    i18nKey: "", // ganti jika key i18next-nya berbeda
                    fetchFile: "",
                    formData: formData,
                });

                if (result.Status == 1) {
                    await Swal.fire({
                        text: result.Keterangan || "Data berhasil dihapus.",
                        icon: "success",
                        buttonsStyling: false,
                        confirmButtonText: "Ok, got it!",
                        customClass: { confirmButton: "btn btn-primary" },
                    });
                } else {
                    // Build error message HTML
                    let errorHtml = result.Keterangan || "Gagal menghapus data.";

                    if (result.listErrorMessage && result.listErrorMessage.length > 0) {
                        errorHtml += "<div style='text-align: left; margin-top: 15px; max-height: 300px; overflow-y: auto;'>";
                        errorHtml += "<strong>Gagal menghapus:</strong><ul style='margin: 10px 0; padding-left: 20px;'>";

                        result.listErrorMessage.forEach((error) => {
                            errorHtml += `<li><strong>${error.NamaPlayer || 'Player'}</strong>: ${error.Keterangan}</li>`;
                        });

                        errorHtml += "</ul></div>";
                    }

                    await Swal.fire({
                        html: errorHtml,
                        icon: "error",
                        buttonsStyling: false,
                        confirmButtonText: "Ok, got it!",
                        customClass: { confirmButton: "btn btn-primary" },
                    });
                }

                // ⚡ return result ke handler agar bisa dicek Status
                return result;
            };

            const dt = await initDatatable({
                tableId,
                formData,
                displayColumns: [
                    { columnName: "IDPlayer", displayedName: "ID", IsShown: false },
                    { columnName: "full_name", displayedName: "Nama Lengkap" },
                    { columnName: "email", displayedName: "Email" },
                    { columnName: "gender", displayedName: "Gender" },
                    {
                        columnName: "photo",
                        displayedName: "Foto Profil",
                        dataType: "image",
                        displayedValue: {
                            path: "../api/assets/player/",
                            additionalpath: "IDPlayer",
                            width: 40,
                            height: 40,
                        },
                    },
                    { columnName: "MembershipNumber", displayedName: "Membership Number" },
                    { columnName: "TanggalExpired", displayedName: "Tanggal Expired" },
                    { columnName: "StatusMembership", displayedName: "Status Membership" },
                    { columnName: "TanggalBayaran", displayedName: "Tanggal Bayar" },
                    { columnName: "PaymentStatus", displayedName: "Status Payment" },
                    { columnName: "ranking_position", displayedName: "Ranking" },
                    { columnName: "total_points", displayedName: "Total Poin" },

                    { columnName: "CreateBy" },
                    {
                        columnName: "CreateAt",
                        dataType: "datetime",
                        displayedValue: {
                            format: "dd-MM-yyyy HH:mm:ss",
                        },
                    },
                    { columnName: "LastUpdateBy" },
                    {
                        columnName: "LastUpdateAt",
                        dataType: "datetime",
                        displayedValue: {
                            format: "dd-MM-yyyy HH:mm:ss",
                        },
                    },
                ],
                allowAction: allowAction,
                viewedit_action_url: "m_player_add.php",
                delete_action_callback: delete_action_callback,
                filterKolom: filterKolom
            });


        }



        KTUtil.onDOMContentLoaded(function () {
            window.onI18nReadyCallbacks = window.onI18nReadyCallbacks || [];
            if (window.i18nReady) {
                starting();
            } else {
                window.onI18nReadyCallbacks.push(starting());
            }
        });

        async function starting() {
            console.log("dashboard - i18n ready");


            let ses_res = null;

            try {
                const res = await checkSession(true);
                if (res?.Status === 1) {
                    ses_res = res;
                }
            } catch (err) {
                console.warn("checkSession failed:", err);
            }

            // === Jika session valid ===
            if (ses_res) {
                console.log("Session valid:", ses_res);
                updateHeaderUser(ses_res.listU || {}, ses_res.listA || {});
                // === Bagian inisialisasi umum ===
                initDynamicLanguageHandler(["header", "generic"]);
                toggleContentOverlay("off");
                load(ses_res.listU || {}, ses_res.listA || {});
            }
        }






    </script>



    <!--end::Custom Javascript-->
    <!--end::Javascript-->
</body>
<!--end::Body-->


</html>