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

import { browser } from '$app/environment';
import { events_func } from '$lib/ae_events/ae_events_functions';

// This file needs to load the Event Badge ID. It should also include the associated Event Badge Template for the specific badge ID.
export async function load({ params, parent, url }) {
    const log_lvl: number = 2;

    const parent_data = await parent();

    const account_id = parent_data.account_id;

    const ae_acct = parent_data[account_id];

    if (browser) {
        if (log_lvl) console.log(`ae_events +page.ts (Non-Blocking Refresh)`);

        const event_id = params.event_id;
        const event_badge_id = params.badge_id;

        if (event_badge_id) {
            // Refresh the specific selected Event Badge ID
            events_func.load_ae_obj_id__event_badge({
                api_cfg: ae_acct.api,
                event_badge_id: event_badge_id,
                event_id: event_id, // This event_id should not be needed here... 2026-02-04
                inc_template: true,
                log_lvl: log_lvl
            });
        }
    }

    return {
        params
    };
}
