const statuses = {
    offline: {
        title: "No Network Connection",
        description: "Connect to a network and try again.",
        icon: "../../icons/network-error-symbolic.svg",
        action: "Try Again",
    },
    forbidden: {
        title: "Access Denied",
        description: "You don’t have permission to view this page.",
        icon: "../../icons/sad-computer-symbolic.svg",
    },
    "not-found": {
        title: "Page Not Found",
        description: "The requested page could not be found.",
        icon: "../../icons/sad-computer-symbolic.svg",
    },
    "load-error": {
        title: "Unable to Load Page",
        description: "Something went wrong while loading this page.",
        icon: "../../icons/sad-computer-symbolic.svg",
        action: "Try Again",
    },
    "page-crashed": {
        title: "Page Crashed",
        description: "The page stopped unexpectedly. Reload it to continue.",
        icon: "../../icons/sad-computer-symbolic.svg",
        action: "Reload Page",
    },
    "page-unresponsive": {
        title: "Page Is Not Responding",
        description: "The page became unresponsive. Reload it to continue.",
        icon: "../../icons/sad-computer-symbolic.svg",
        action: "Reload Page",
    },
};

const requestedType = new URLSearchParams(window.location.search).get("type");
const status = statuses[requestedType] || statuses["load-error"];

document.title = status.title;
document.getElementById("status-icon").src = status.icon;
document.getElementById("status-title").textContent = status.title;
document.getElementById("status-description").textContent = status.description;

const action = document.getElementById("status-action");
const retryURL = new URLSearchParams(window.location.search).get("retry");
if (status.action && retryURL) {
    try {
        const parsedRetryURL = new URL(retryURL);
        if (["http:", "https:", "file:"].includes(parsedRetryURL.protocol)) {
            action.textContent = status.action;
            action.hidden = false;
            action.addEventListener("click", () => window.location.assign(parsedRetryURL.href));
        }
    } catch (error) {
        // Leave the action hidden when the retry target is malformed.
    }
}
