import type { PageServerLoad } from './$types'; import { apiClient } from '$lib/server/api'; import { getWeekStart } from '$lib/planner/week'; export const load: PageServerLoad = async ({ fetch, url }) => { const weekParam = url.searchParams.get('week'); const weekStart = weekParam ?? getWeekStart(new Date()); const api = apiClient(fetch); const { data: weekPlan, error: weekPlanError } = await api.GET('/v1/week-plans', { params: { query: { weekStart } } }); if (weekPlanError || !weekPlan?.id) { return { weekPlan: null, varietyScore: null, weekStart }; } const { data: varietyScore } = await api.GET('/v1/week-plans/{id}/variety-score', { params: { path: { id: weekPlan.id } } }); return { weekPlan, varietyScore: varietyScore ?? null, weekStart }; };