import { Hono } from "npm:hono";
import { html } from "npm:hono/html";
import type { Child, FC } from "npm:hono/jsx";
import { jsxRenderer, useRequestContext } from "npm:hono/jsx-renderer";
const app = new Hono();
const Nav: FC = () => {
return (
<div id="menu" hx-boost="true" hx-target="#main">
<nav>
<a href="/">Home</a>
<a href="/test_page">Test Page</a>
</nav>
</div>
);
};
const Main: FC<{ children: Child }> = ({ children }) => {
return (
<main id="main" class="h-full">
{children}
</main>
);
};
const Page: FC<{ children: Child }> = ({ children }) => {
return (
<html>
<head>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
</meta>
<script type="module" src="https://cdn.skypack.dev/twind/shim"></script>
<script src="https://unpkg.com/htmx.org@1.9.9"></script>
<script type="module" src="https://esm.town/v/saolsen/test_game_browser" defer></script>
<script type="module" src="https://esm.town/v/saolsen/test_game_server" defer></script>
</head>
<body class="h-screen">
<Main children={children}></Main>
</body>
</html>
);
};
const Layout: FC<{ children: Child }> = ({ children }) => {
const c = useRequestContext();
const hx_target = c.req.header("hx-target");
switch (hx_target) {
case undefined: {
return <Page children={children}></Page>;
}
case "main": {
return <Main children={children}></Main>;
}
default: {
return <>{children}</>;
}
}
};
app.use("*", jsxRenderer(({ children }) => <Layout children={children}></Layout>));
app.get("/", (c) => {
return c.render(
<div class="flex flex-col h-full">
<div class="flex-grow flex items-center justify-center">
<div id="wrapper" class="w-full h-full overflow-hidden flex items-center justify-center">