/** @type {import('./$types').LayoutLoad} */
// console.log(`IDAA Recovery Meetings - [account_id] +layout.ts start`);

// import { error } from '@sveltejs/kit';
import { browser } from '$app/environment';
import { events_func } from '$lib/ae_events_functions';

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

	const data = await parent();
	data.log_lvl = log_lvl;

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

	// if (!account_id) {
	//     console.log(`ae IDAA Recovery Meetings - [account_id] +page.ts: The account_id was not found!!!`);
	//     error(404, {
	// 		message: 'Account ID not found'
	// 	});
	// }

	// ae_acct.slct.account_id = account_id;

	if (browser) {
		const load_event_obj_li = events_func.load_ae_obj_li__event({
			api_cfg: ae_acct.api,
			for_obj_type: 'account',
			for_obj_id: account_id,
			qry_conference: false,
			hidden: 'not_hidden', // 'not_hidden'
			enabled: 'enabled',
			order_by_li: {
				priority: 'DESC',
				sort: 'DESC',
				updated_on: 'DESC',
				created_on: 'DESC',
				name: 'ASC'
			},
			limit: 199,
			try_cache: true,
			log_lvl: log_lvl
		});
		if (log_lvl) {
			console.log(`load_event_obj_li = `, load_event_obj_li);
		}
		ae_acct.slct.event_obj_li = load_event_obj_li;
	}

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

	return data;
}
