import { Head } from "fresh/runtime";
import { define } from "../utils.ts";
import { getHero } from "../lib/heroes.ts";
import CharacterCreation from "../islands/CharacterCreation.tsx";
import Game from "../islands/Game.tsx";
export const handler = define.handlers({
async GET(ctx) {
if (!ctx.state.user) return ctx.redirect("/login");
const hero = await getHero(ctx.state.user.id);
if (!hero) {
return ctx.render(
<>
<Head>
<title>Profectus — Forge your hero</title>
</Head>
<CharacterCreation />
</>,
);
}
return ctx.render(
<>
<Head>
<title>Profectus</title>
</Head>
<Game hero={hero} isAdmin={ctx.state.user.role === "admin"} />
</>,
);
},
});
export default function Index() {
return null;
}