/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

use crate::{RenderInfo, page};
use jellyui_locale::tr;

page!(AccountLogin<'_>, |x| tr(x.ri.lang, "account.login"));
page!(AccountLogout<'_>, |x| tr(x.ri.lang, "account.logout"));
page!(AccountSetPassword<'_>, |x| tr(
    x.ri.lang,
    "account.login.set_password"
));

markup::define! {
    AccountSetPassword<'a>(ri: &'a RenderInfo<'a>, username: &'a str, password: &'a str) {
        form.account[method="POST", action=""] {
            h1 { @tr(ri.lang, "account.login.set_password") }
            p { @tr(ri.lang, "account.login.set_password.par") }

            input[type="hidden", name="username", value=username];
            input[type="hidden", name="password", value=password];

            label[for="password"] { @tr(ri.lang, "account.new_password") }
            input[type="password", id="password", name="new_password"]; br;

            label[for="display_name"] { @tr(ri.lang, "account.display_name") }
            input[type="text", id="display_name", name="display_name"]; br;

            input[
                type="submit",
                value=tr(ri.lang, "account.login.set_password.submit"),
                "data-loading-text"=tr(ri.lang, "account.login.submit.loading")
            ];
        }
    }
    AccountLogin<'a>(ri: &'a RenderInfo<'a>) {
        form.account[method="POST", action=""] {
            h1 { @tr(ri.lang, "account.login") }

            label[for="username"] { @tr(ri.lang, "account.username") }
            input[type="text", id="username", name="username"]; br;
            label[for="password"] { @tr(ri.lang, "account.password") }
            input[type="password", id="password", name="password"]; br;

            input[
                type="submit",
                value=tr(ri.lang, if ri.user.is_some() { "account.login.submit.switch" } else { "account.login.submit" }),
                "data-loading-text"=tr(ri.lang, if ri.user.is_some() { "account.login.submit.switch.loading" } else { "account.login.submit.loading" })
            ];
        }
    }
    AccountLogout<'a>(ri: &'a RenderInfo<'a>) {
        form.account[method="POST", action=""] {
            h1 { @tr(ri.lang, "account.logout") }
            input[
                type="submit",
                value=tr(ri.lang, "account.logout.submit"),
                "data-loading-text"=tr(ri.lang, "account.logout.submit.loading")
            ];
        }
    }
}
