/** @type {import('./$types').PageLoad} */
console.log(`ae_events_leads [slug] +page.ts start`);

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

export async function load({ params, parent }) {
	// route
	const log_lvl: number = 0;

	const data = await parent();
	// console.log(`ae_events_leads exhibit [slug] +page.ts data:`, data);

	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 exhibit [slug] +page.ts: The account_id was not found in the data!!!`
		);
		return false;
	}

	data.ae_events_leads_exhibit_slug_page_ts = true;

	const event_exhibit_id = params.slug;
	if (!event_exhibit_id) {
		console.log(
			`events_leads exhibit [slug] +page.ts: The event_exhibit_id was not found in the params.slug!!!`
		);
		return false;
	}

	ae_acct.slct.event_exhibit_id = event_exhibit_id;

	const load_event_exhibit_obj = events_func.handle_load_ae_obj_id__exhibit({
		api_cfg: ae_acct.api,
		exhibit_id: event_exhibit_id,
		try_cache: false
	});

	ae_acct.slct.event_exhibit_obj = await load_event_exhibit_obj;

	const load_event_exhibit_tracking_obj_li = events_func.handle_load_ae_obj_li__exhibit_tracking({
		api_cfg: ae_acct.api,
		exhibit_id: event_exhibit_id,
		params: { enabled: 'all', qry__limit: 550 },
		try_cache: false
	});
	console.log(`load_event_exhibit_tracking_obj_li = `, load_event_exhibit_tracking_obj_li);

	ae_acct.slct.event_exhibit_tracking_obj_li = load_event_exhibit_tracking_obj_li;

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

	return data;
}
