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=qualifying")
	if(res.ok){
		content = (await res.json()).content
	}
	res = await fetch("/api/qualifying")
	if(res.ok){
		exams = await res.json()
	}
    const events:CalendarEvent[]=[]
    exams.forEach(({id,title,start,institute_id})=>{
        let backgroundColor =""
        switch (institute_id) {
            case 1:
                backgroundColor="rgba(251,64,75,.2)"
                break;
            case 2:
                backgroundColor="#23ccef"
                break;
            case 3:
                backgroundColor="rgba(68,125,247,.2)"
                break;
            default:
                break;
        }
        const url = "/qualifying/"+id
        events.push({id,title,start,url,backgroundColor})
    })
    return {exams,events,content}
}

