import { notFound } from "next/navigation";
import { api } from "@/server/api/client";
import { TRPCError } from "@trpc/server";
import DayView from "@/components/dashboard/days/DayView";

export default async function DayPage({
    params,
}: {
    params: { dateQuery: string };
}) {
    let day;
    try {
        day = await api.days.get({
            dateQuery: params.dateQuery,
        });
    } catch (e) {
        if (e instanceof TRPCError) {
            if (e.code == "NOT_FOUND") {
                notFound();
            }
        }
        throw e;
    }

    return (
        <DayView
            day={day}
        />
    );
}
