/** @type {import('./$types').LayoutLoad} */
console.log(`ae_events_leads +layout.ts start`);

import { events_func } from '$lib/ae_events_functions';

export async function load({ parent }) {
	const data = await parent();

	const account_id = data.account_id;
	const ae_acct = data[account_id];
	console.log(`ae_acct = `, ae_acct);

	if (!account_id) {
		console.log(`events_leads +layout.ts: The account_id was not found in the data!!!`);
		return false;
	}

	const event_id = ae_acct.slct.event_id;
	if (!event_id) {
		console.log(`events_leads +layout.ts: The event_id was not found in the data!!!`);
		return false;
	}

	const load_event_obj = events_func.load_ae_obj_id__event({
		api_cfg: ae_acct.api,
		event_id: event_id,
		try_cache: true
	});

	ae_acct.slct.event_obj = load_event_obj;

	const load_event_exhibit_obj_li = events_func.handle_load_ae_obj_li__exhibit({
		api_cfg: ae_acct.api,
		event_id: event_id,
		try_cache: false
	});
	console.log(`load_event_exhibit_obj_li = `, load_event_exhibit_obj_li);

	ae_acct.slct.event_exhibit_obj_li = load_event_exhibit_obj_li;

	// WARNING: Precaution against shared data between sites and sessions.
	data[account_id] = ae_acct;

	return data;
}

// export const prerender = false;
// export const prerender = true;
