use tablo_ui::{card, card_content, card_description, card_header};
use topcoat::{
context::Cx,
view::{BoxView, ViewExt, view},
};
use super::realm::hosted;
pub(super) struct AuthPage<'a> {
pub(super) title: String,
pub(super) description: String,
pub(super) status: Option<http::StatusCode>,
pub(super) form: BoxView<'a>,
pub(super) switch: Option<BoxView<'a>>,
pub(super) note: Option<String>,
}
pub(super) async fn render<'a>(cx: &'a Cx, page: AuthPage<'a>) -> topcoat::Result<BoxView<'a>> {
let AuthPage {
title,
description,
status,
form,
switch,
note,
} = page;
let host = hosted(cx)?;
let brand = host.page_brand(cx);
let heading = title.clone();
let body = view! {
<main
class="flex min-h-svh flex-col items-center justify-center gap-6 bg-background p-6"
>
if let Some(status) = status {
(status)
}
(brand)
card(
attrs: topcoat::view::attributes! { class="w-full max-w-sm" },
card_header(
<h1 class="text-xl leading-none font-semibold tracking-tight">
(heading)
</h1>
card_description((description))
)
card_content((form))
)
if let Some(switch) = switch {
<p class="text-center text-sm text-muted-foreground">(switch)</p>
}
if let Some(note) = note {
<p
class="max-w-sm text-center text-xs text-muted-foreground"
data-login-hint=""
>
(note)
</p>
}
</main>
}
.boxed();
host.document(cx, title, body).await
}
pub(super) fn switch_link<'a>(
cx: &'a Cx,
prompt: &'static str,
href: &str,
label: &'static str,
) -> BoxView<'a> {
let link = crate::navigation::runtime_link(cx, href);
let (prompt, label) = (crate::t!(cx, prompt), crate::t!(cx, label));
view! {
(prompt)
" "
<a
(link)
class="font-medium text-foreground underline underline-offset-4 hover:text-primary"
>
(label)
</a>
}
.boxed()
}