import { raw } from "hono/html";
import type { Child } from "hono/jsx";
import type { AgendaDay, AgendaItem } from "./agenda.js";
import { formatDayHeading, formatTime, LOCALES, type Locale, type MessageKey, t } from "./i18n.js";
import { styles } from "./styles.js";
type LayoutProps = { locale: Locale; isMock: boolean; children?: Child };
function Layout({ locale, isMock, children }: LayoutProps) {
return (
{t(locale, "app.name")}
{isMock && (
{t(locale, "mock.banner")}
)}
{children}
);
}
export const NOTICES = ["denied", "failed", "setup", "browser", "consent"] as const;
export type Notice = (typeof NOTICES)[number];
/** Календарь не подключён: что это, что сделать и что будет дальше. */
export function ConnectPage(props: {
locale: Locale;
isMock: boolean;
notice?: Notice | null;
/** Подключение не удалось уже не в первый раз: подсказка другая. */
repeated?: boolean;
/** Образец списка (у мока): показывается под кнопкой и помечен как образец. */
sample?: { days: AgendaDay[]; timeZone: string } | null;
}) {
const { locale, notice } = props;
return (
{props.sample && (
{t(locale, "sample.title")}
{t(locale, "sample.lead")}
)}
);
}
/** Сообщение из двух фраз и одно действие. */
export function MessagePage(props: {
locale: Locale;
isMock: boolean;
title: MessageKey;
message: MessageKey;
action: { href: string; label: MessageKey };
}) {
const { locale } = props;
return (
);
}
function Item({ item, locale, timeZone }: { item: AgendaItem; locale: Locale; timeZone: string }) {
const when =
item.kind === "timed" && item.start
? formatTime(locale, item.start, timeZone)
: t(locale, item.kind === "ongoing" ? "agenda.ongoing" : "agenda.allDay");
return (
{when}
{item.title ?? t(locale, "agenda.untitled")}
);
}
function DayList({
days,
locale,
timeZone,
}: {
days: AgendaDay[];
locale: Locale;
timeZone: string;
}) {
return (
<>
{days.map((day) => (
{formatDayHeading(locale, day.key, day.offset)}
{day.items.map((item) => (
))}
))}
>
);
}
/** Календарь подключён: список на 7 дней или сообщение о пустой неделе. Только просмотр. */
export function AgendaPage(props: {
locale: Locale;
isMock: boolean;
days: AgendaDay[];
timeZone: string;
}) {
const { locale, days, timeZone } = props;
return (
{t(locale, "agenda.title")}
{t(locale, "agenda.connected")}
{t(locale, "agenda.lead")}
{days.length === 0 ? (
{t(locale, "agenda.empty")}
{t(locale, "agenda.emptyHint")}
) : (
)}
);
}