<script lang="ts">
interface Props {
    /** @type {import('./$types').PageData} */
    data: any;
}

let { data }: Props = $props();
let log_lvl: number = $state(0);

// Imports
import { untrack } from 'svelte';
import { ae_loc, ae_sess, ae_api } from '$lib/stores/ae_stores';
import {
    events_sess,
    events_slct
} from '$lib/stores/ae_events_stores';

// NOTE: Derived from data.account_id (prop) instead of $slct.account_id (store)
// to prevent circular dependency loops during hydration.
let ae_acct = $derived(data[data.account_id]);

let url_event_id = $derived(data.params.event_id);
let url_event_location_id = $derived(data.params.event_location_id);

$effect(() => {
    if (log_lvl > 1) {
        console.log(`event_id: ${url_event_id}`);
        console.log(`event_location_id: ${url_event_location_id}`);
    }
    untrack(() => {
        $events_slct.event_id = url_event_id;
        $events_slct.event_location_id = url_event_location_id;
    });
});

$effect(() => {
    if (ae_acct) {
        untrack(() => {
            $events_slct.event_location_obj_li = ae_acct.slct
                .event_location_obj_li ?? [''];
            $events_slct.id_li__event_location = ae_acct.slct
                .id_li__event_location ?? [''];
            $events_slct.event_session_obj_li = ae_acct.slct
                .event_session_obj_li ?? [''];
        });
    }
});

// WHY: launcher_loc is a PersistedState store — always initialized with defaults from
// launcher_loc_defaults. No initialization guards needed; all fields (slct, show_content__*)
// are already set to their default values on first load.

// Set session storage defaults
if (!$events_sess.launcher) $events_sess.launcher = {};
$events_sess.launcher.show_content__session_code = true;
$events_sess.launcher.show_content__presentation_code = true;
$events_sess.launcher.show_content__presenter_code = true;
</script>

<div class="hidden">This is for forcing data loading.</div>
