import type { PageLoad } from './$types';

// Data loading for IDAA BB [post_id] has been moved to the $effect in bb/+layout.svelte
// (triggered via $idaa_trig.post_id, gated inside the auth-verified layout render).
// +page.ts runs before layout effects and fires during SvelteKit link prefetch,
// making it unsafe for private IDAA content.

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

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

    const account_id = data.account_id;
    let ae_acct = data[account_id];

    if (!ae_acct) {
        console.warn(
            `ae IDAA BB [post_id] +page.ts: Account ${account_id} not found in data. Initializing ghost acct.`
        );
        ae_acct = {
            api: data.ae_api || {},
            slct: { account_id: account_id }
        };
    }

    ae_acct.slct.post_id = params.post_id;

    data[account_id] = ae_acct;
    return data;
}) satisfies PageLoad;
