<script lang="ts">
	let log_lvl: number = 0;

	// *** Import Svelte specific
	import { page } from '$app/state';

	// *** Import Aether specific variables and functions
	import {
		ae_snip,
		ae_loc,
		ae_sess,
		ae_api,
		ae_trig,
		slct,
		slct_trigger
	} from '$lib/stores/ae_stores';
	import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } from '$lib/stores/ae_idaa_stores';
	import { events_func } from '$lib/ae_events_functions';

	interface Props {
		/** @type {import('./$types').LayoutData} */
		data: any;
		children?: import('svelte').Snippet;
	}

	let { data, children }: Props = $props();

	if (log_lvl > 1) {
		console.log(`ae_idaa_recovery_meetings +layout.svelte`, data);
	}

	// *** Quickly pull out data from parent(s)
	$slct.account_id = data.account_id;

	let ae_acct = data[$slct.account_id];
	if (log_lvl) {
		console.log(`ae_acct = `, ae_acct);
	}

	$idaa_slct.event_obj_li = ae_acct.slct.event_obj_li;
	// $idaa_slct.event_id = ae_acct.slct.event_id; // Not set here yet.

	// *** Set initial variables

	// $effect(() => {
	//     if ($idaa_trig.event_id && $idaa_slct.event_id) {
	//         log_lvl = 1;
	//         $idaa_trig.event_id = false;

	//         if (log_lvl) {
	//             console.log(`Triggered: $idaa_slct.event_id = ${$idaa_slct.event_id}`);
	//         }

	//         $idaa_prom.load__event_obj = events_func.load_ae_obj_id__event({
	//             api_cfg: $ae_api,
	//             event_id: $idaa_slct.event_id,
	//             // enabled: $idaa_loc.recovery_meetings.qry__enabled,
	//             // hidden: $idaa_loc.recovery_meetings.qry__hidden,
	//             // limit: $idaa_loc.recovery_meetings.qry__limit,
	//             try_cache: true,
	//             log_lvl: log_lvl,
	//         })
	//         .then((event_obj) => {
	//             if (log_lvl) {
	//                 console.log(`Event object loaded: `, event_obj);
	//             }

	//             $idaa_slct.event_obj = event_obj;

	//             // $idaa_sess.recovery_meetings.show__modal_view = $idaa_slct.event_id;
	//             // $idaa_sess.recovery_meetings.show__modal_edit = false;
	//         });

	//         // $idaa_slct.event_obj = $idaa_prom.load__event_obj;

	//         if (!page.url.searchParams.get('event_id')) {
	//             const url = new URL(location);
	//             // url.searchParams.set('event_id', $idaa_slct.event_id);
	//             url.searchParams.delete('event_id');
	//             history.pushState({}, '', url);

	//             let message = {'event_id': $idaa_slct.event_id};
	//             window.parent.postMessage(message, "*");
	//         }

	//         // $idaa_sess.recovery_meetings.show__modal_view = $idaa_slct.event_id;
	//         // $idaa_sess.recovery_meetings.show__modal_view__event_id = $idaa_slct.event_id;
	//         // $idaa_sess.recovery_meetings.show__modal_edit = false;
	//         // $idaa_sess.recovery_meetings.show__modal_edit__event_id = false;

	//     }
	// });
</script>

{@render children?.()}
