import spacetime from "spacetime";
import { createClient } from '@/utils/supabase/server';
import RealtimeDayPage from "./realtime";

export default async function DayPage(
    { params }: { params: { date: string } }
) {
    const supabase = await createClient();
    const date = (await params).date;

    const { data: { user: user } } = await supabase.auth.getUser();
    const { data: day } = await supabase
        .from('days')
        .select(`*, 
            hours(*, 
                category:categories(id,
                    code,
                    name,
                    color:colors(name, hexcode, inverse)
                )   
            )
            `)
        .eq('date', date)
        .eq('userId', user?.id)
        .limit(1).single()
        ;

    return !day ? <div>Loading...</div> : (
        <RealtimeDayPage initialDay={day} />
    );
}
