import { e } from "./helper.ts"
import { tryLoadAdminPanel } from "./admin.ts"

export function pw_modal() {
    const inp_name  = e("input", {type: "text",     placeholder: "Username"})
    const inp_pw    = e("input", {type: "password", placeholder: "Password"})
    const error_msg = e("span", {class: "error-msg"}, "")
    const login_btn = e("button", {
        onclick: ev => {
            ev.preventDefault()
            tryLoadAdminPanel(inp_name.value, inp_pw.value).catch(err => {
                error_msg.textContent = err
            })
        }
    }, "Login")

    return e("dialog", {},
        e("form", {method: "dialog"},
            inp_name,
            inp_pw,
            login_btn,
            error_msg,
        )
    )
}
