<script lang="ts">
interface Props {
    container_class_li?: string | Array<string>;
    lq__event_session_obj_li?: any; // New Shared Observable Pattern
    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?: boolean;
    hide__location_link?: boolean;
    log_lvl?: number;
}

let {
    container_class_li = [],
    lq__event_session_obj_li: lq__shared,
    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 = $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';

// Logic: Use shared observable if provided, otherwise create internal one
let lq__event_session_obj_li = $derived.by(() => {
    if (lq__shared) return lq__shared;

    return liveQuery(async () => {
        if (link_to_type && link_to_id) {
            const results = await db_events.session
                .where(`${link_to_type}_id`)
                .equals(link_to_id)
                .sortBy('start_datetime');
            return results;
        } else if (event_session_id_random_li.length > 0) {
            const results = await db_events.session.bulkGet(
                event_session_id_random_li
            );
            return results.filter((item) => item !== undefined);
        }
        return null;
    });
});
</script>

<Comp_event_session_obj_li
    {container_class_li}
    {lq__event_session_obj_li}
    {hide__session_location}
    {hide__session_poc}
    {hide__admin}
    {hide__launcher_link}
    {hide__location_link}
    {log_lvl}></Comp_event_session_obj_li>
