/** @type {import('./$types').PageLoad} */
import { error } from '@sveltejs/kit';
console.log(`ae_p_journals [journal_id] +page.ts start`);

import { browser } from '$app/environment';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';

export async function load({ params, parent }) {
	// route
	// let log_lvl: number = 1;
	// let data = await parent();
	// data.log_lvl = log_lvl;
	// let account_id = data.account_id;
	// let ae_acct = data[account_id];
	// let journal_id = params.journal_id;
	// if (!journal_id) {
	//     console.log(`ae_journals journals [journal_id] +page.ts: The journal_id was not found in the params!!!`);
	//     error(404, {
	// 		message: 'Journals - Journal ID not found'
	// 	});
	// }
	// ae_acct.slct.journal_id = journal_id;
	// console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, ae_acct.slct.journal_id);
	// if (browser) {
	//     if (log_lvl) {
	//         console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
	//     }
	//     // Load event journal object
	//     let load_journal_obj = journals_func.load_ae_obj_id__journal({
	//         api_cfg: ae_acct.api,
	//         journal_id:  journal_id,
	//         inc_entry_li: true,
	//         try_cache: true,
	//         log_lvl: log_lvl
	//     });
	//     ae_acct.slct.journal_obj = load_journal_obj;
	// Load journal entries for the journal
	// let load_journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
	//     api_cfg: ae_acct.api,
	//     for_obj_type: 'journal',
	//     for_obj_id: journal_id,
	//     params: {qry__enabled: 'all', qry__limit: 99},
	//     try_cache: true
	// })
	// .then((journal_entry_obj_li) => {
	//     if (log_lvl) {
	//         console.log(`journal_entry_obj_li = `, journal_entry_obj_li);
	//     }
	//     for (let index = 0; index < journal_entry_obj_li.length; index++) {
	//         let journal_entry_obj = journal_entry_obj_li[index];
	//         let journal_entry_id = journal_entry_obj.journal_entry_id_random;
	//         let load_journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
	//             api_cfg: ae_acct.api,
	//             for_obj_type: 'journal_entry',
	//             for_obj_id: journal_entry_id,
	//             params: {qry__enabled: 'all', qry__limit: 15},
	//             try_cache: true
	//         });
	//         if (log_lvl) {
	//             console.log(`load_journal_entry_obj_li = `, load_journal_entry_obj_li);
	//         }
	//         journal_entry_obj_li[index].journal_entry_li = load_journal_entry_obj_li;
	//     }
	//     return journal_entry_obj_li;
	// });
	// if (log_lvl) {
	//     console.log(`load_journal_entry_obj_li = `, load_journal_entry_obj_li);
	// }
	// ae_acct.slct.journal_entry_obj_li = load_journal_entry_obj_li;
	// }
	// WARNING: Precaution against shared data between sites.
	// data[account_id] = ae_acct;
	// return data;
}
