import type { PageServerLoad } from './$types'
import type {CalendarEvent} from '$lib/components/CalendarEvent'
import type {Exam} from '$lib/components/Exam' 

export const load: PageServerLoad = async ({fetch}) => {
	let content = ""
    let exams:Exam[] = []
	let res = await fetch("/api/content?page=competitive")
	if(res.ok){
		content = (await res.json()).content
	}

	res = await fetch("/api/competitive")
	if(res.ok){
		exams = await res.json()
	}

    const events:CalendarEvent[]=[]
    exams.forEach(({id,title,start})=>{
        const backgroundColor ="#9999FF"
        const url = "/competitive/"+id
        events.push({id,title,start,url,backgroundColor})
    })
    return {content,exams,events}
}