// Copyright (C) 2025-2026 Cian-H/iform-invenio (I-Form).
//
// invenio-theme-iform is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import $ from "jquery";

async function generateForm() {
    // get email from `/api/me`
    let email = "???";
    const response = await fetch("/api/me");
    if (response.ok) {
        const json = await response.json();
        email = json?.email || "???";
    }

    // show message
    $("#anchor-unlock-form").html(
        `<div class="ui warning message">
            <div class="header">Account Unlocking</div>
            <p>Please contact an administrator to request unlocking for your account (${email}).</p>
        </div>`
    );
}

$(function () {
    // called when DOM is ready
    const generateFormElement = document.getElementById("generate-unlock-form");
    if (generateFormElement) {
        generateFormElement.onclick = generateForm;
    }
});
