import type { PageLoad } from './$types';
import { error } from '@sveltejs/kit';
import { load_ae_obj_id__user } from '$lib/ae_core/ae_core__user';
import { get } from 'svelte/store';
import { ae_api } from '$lib/stores/ae_stores';

export const load: PageLoad = async ({ params, parent }) => {
    const parentData = await parent();
    const { user_id } = params;

    if (!user_id) {
        error(404, 'User ID not specified');
    }

    const user = await load_ae_obj_id__user({
        api_cfg: get(ae_api),
        user_id,
        log_lvl: 1
    });

    if (!user) {
        error(404, 'User not found');
    }

    return {
        user
    };
};
