document.addEventListener("DOMContentLoaded", async () => {
    try {
        const response = await fetch("/api/v1/frontend/response/");

        if (!response.ok) {
            console.error(`HTTP ${response.status}`);
            return;
        }

        const data = await response.json();

        if (!Object.keys(data).length) {
            return;
        }

        const type = Object.keys(data)[0];
        const messageKey = data[type];

        Toastify({
            text: `${type.charAt(0).toUpperCase() + type.slice(1)}: ${__(messageKey)}`,
            duration: 2000,
            gravity: "top",
            position: "right",
            close: true,
            stopOnFocus: true,
            className: `toast-${type}`
        }).showToast();

        if ($.fn.select2) {
            $("#multiple").select2({
                theme: "bootstrap"
            });
        }

    } catch (err) {
        console.error("Failed to retrieve response message:", err);
    }
});