import { MainLayout } from "@components/layouts/main.tsx";
import { Handlers, PageProps } from "$fresh/server.ts";
import { getCacheInfo } from "@lib/cache.ts";

export const handler: Handlers<
  { cacheInfo: ReturnType<typeof getCacheInfo> }
> = {
  GET(_, ctx) {
    return ctx.render({ cacheInfo: getCacheInfo() });
  },
};

export default function Greet(
  props: PageProps<
    { cacheInfo: ReturnType<typeof getCacheInfo> }
  >,
) {
  const { cacheInfo } = props.data;
  return (
    <MainLayout
      url={props.url}
      title="Recipes"
      context={{ type: "recipes" }}
    >
      <code>
        <pre class="text-white">
          {JSON.stringify(cacheInfo, null, 2)}
        </pre>
      </code>
    </MainLayout>
  );
}
