import type { PageServerLoad } from './$types';
import { fetchRandomVerse } from '$lib/server/bible-api';
import { getBookById } from '$lib/server/bible';

export const load: PageServerLoad = async () => {
	const apiVerse = await fetchRandomVerse();

	// Create a dailyVerse-like object for VerseDisplay
	const dailyVerse = {
		id: 'debug-' + Date.now(),
		date: new Date().toLocaleDateString('en-CA', { timeZone: 'America/New_York' }),
		bookId: apiVerse.bookId,
		reference: apiVerse.reference,
		verseText: apiVerse.verseText,
		createdAt: new Date()
	};

	const correctBook = getBookById(dailyVerse.bookId) ?? null;

	return {
		dailyVerse,
		correctBookId: dailyVerse.bookId,
		correctBook
	};
};
