import type { PageLoad } from './$types';
import { ae_api, ae_loc } from '$lib/stores/ae_stores';
import { load_jitsi_report } from '$lib/ae_reports/reports_functions';
import { get } from 'svelte/store';

export const load: PageLoad = async ({ fetch }) => {
	console.log('*** /idaa/jitsi_reports/+page.ts ***');

	const api_cfg = get(ae_api);
	const account_id = get(ae_loc)?.account_id;

	if (!api_cfg || !account_id) {
		console.error('API config or Account ID not available for loading Jitsi reports.');
		return {
			streamed: {
				meetings: Promise.resolve([])
			}
		};
	}

	const meetings_promise = load_jitsi_report({
		api_cfg,
		account_id,
		log_lvl: 1
	});

	return {
		streamed: {
			meetings: meetings_promise
		}
	};
};
