import { env } from '$env/dynamic/private'
import type {Exam} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({params,fetch}) => {
    const id =  params.id+""
	const res = await fetch(env.API_QUALIFYING_URL+"/qualifying/"+id)
	if(res.status==404){
		throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
	}
	if(!res.ok){
		throw error(500,{message:`พบข้อผิดพลาดเกี่ยวกับข้อมูลสอบคัดเลือก ${id}`})
	}
    const post:Exam = await res.json()
	post.date=dayjs(post.announcement_startDate).format("DD MMM BBBB")
    return post
}

