import type { PageLoad } from './$types';

// Disable SSR so the load function runs on the client with the correct local date
export const ssr = false;

export const load: PageLoad = async ({ fetch, data }) => {
	const localDate = new Date().toLocaleDateString("en-CA");

	const res = await fetch('/api/daily-verse', {
		method: 'POST',
		headers: { 'Content-Type': 'application/json' },
		body: JSON.stringify({ date: localDate }),
	});

	const result = await res.json();

	return {
		...data,
		dailyVerse: result.dailyVerse,
		correctBookId: result.correctBookId,
		correctBook: result.correctBook,
	};
};
