<script lang="ts">
	interface Props {
		// Exports
		container_class_li?: string | Array<string>;
		// export let display_mode: string = 'default'; // 'default', 'compact', 'minimal', 'launcher'
		event_session_id_random_li?: Array<string>;
		link_to_type?: string;
		link_to_id?: string;
		hide__session_location?: boolean;
		hide__session_poc?: boolean;
		hide__admin?: boolean;
		hide__launcher_link_legacy?: boolean;
		hide__launcher_link?: boolean;
		hide__location_link?: boolean;
		log_lvl?: number;
	}

	let {
		container_class_li = [],
		event_session_id_random_li = [],
		link_to_type,
		link_to_id,
		hide__session_location = $bindable(false),
		hide__session_poc = $bindable(false),
		hide__admin = $bindable(false),
		hide__launcher_link_legacy = $bindable(false),
		hide__launcher_link = $bindable(false),
		hide__location_link = $bindable(false),
		log_lvl = 0
	}: Props = $props();

	// Imports
	import Comp_event_session_obj_li from './ae_comp__event_session_obj_li.svelte';

	import { liveQuery } from 'dexie';
	import { db_events } from '$lib/ae_events/db_events';

	if (log_lvl > 1) {
		console.log(`event_session list: link_to_type: ${link_to_type}; link_to_id: ${link_to_id}`);
		console.log(`event_session list: event_session_id_random_li: ${event_session_id_random_li}`);
	}

	// Variables
	// let ae_promises: key_val = {};
	// let ae_tmp: key_val = {};
	// let ae_triggers: key_val = {};

	let dq__where_type_id_val: string = `${link_to_type}_id_random`;
	let dq__where_eq_id_val: string = link_to_id ?? '';

	let lq__event_session_obj_li = $derived(
		liveQuery(async () => {
			if (link_to_type && link_to_id) {
				let results = await db_events.session
					.where(dq__where_type_id_val)
					.equals(dq__where_eq_id_val)
					// .sortBy('name')
					.sortBy('start_datetime');
				// This should be sorted by a custom sort field

				return results;
			} else if (event_session_id_random_li.length > 0) {
				let results = await db_events.session.bulkGet(event_session_id_random_li);

				return results;
			} else {
				return null;
			}
		})
	);

	// *** Functions and Logic
</script>

<!-- {#if $lq__event_session_obj_li?.length > 0} -->
<Comp_event_session_obj_li
	{container_class_li}
	{lq__event_session_obj_li}
	{hide__session_location}
	{hide__session_poc}
	{hide__admin}
	{hide__launcher_link_legacy}
	{hide__launcher_link}
	{hide__location_link}
	{log_lvl}
></Comp_event_session_obj_li>
<!-- {/if} -->
