import { type AppProps, Handlers, PageProps } from "$fresh/server.ts";
import { Page } from "@/components/Page.tsx";
import { type PublicUser } from "@/types.ts";
import { type ContextState } from "@/types.ts";

interface MyAppProps extends AppProps {
  user?: PublicUser;
}

export const handler: Handlers<unknown, ContextState> = {
  async GET(request: Request, context) {
    console.log("AppHandler:", request, context);
    return await context.render(context.state.user);
  },
};

export default function App({ Component, ...props }: MyAppProps) {
  console.log("AppProps:", props);
  return (
    <Page user={props.user}>
      <Component></Component>
    </Page>
  );
}
