<script lang="ts">
interface Props {
    container_class_li?: string | Array<string>;
    display_mode?: string; // 'default', 'compact', 'minimal', 'launcher'
    event_presenter_id_li?: Array<string>;
    event_presenter_id_random_li?: Array<string>;
    link_to_type: string;
    link_to_id: string;
    // export let lq__event_presentation_obj
    log_lvl?: number;
}

let {
    container_class_li = [],
    display_mode = 'default',
    event_presenter_id_li = [],
    event_presenter_id_random_li = [],
    link_to_type,
    link_to_id,
    log_lvl = 0
}: Props = $props();

// Imports
import Comp_event_presenter_obj_li from './ae_comp__event_presenter_obj_li.svelte';

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

$effect(() => {
    if (log_lvl) {
        console.log(`link_to_type: ${link_to_type}; link_to_id: ${link_to_id}`);
    }
});

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

let dq__where_type_id_val = $derived(`${link_to_type}_id`);
let dq__where_eq_id_val = $derived(link_to_id);

// *** Functions and Logic
let lq__event_presenter_obj_li = $derived(
    liveQuery(async () => {
        if (link_to_type && link_to_id) {
            let results = await db_events.presenter
                .where(dq__where_type_id_val)
                .equals(dq__where_eq_id_val)
                .sortBy('full_name');

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

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

            return results;
        } else {
            return null;
        }
    })
);
</script>

<Comp_event_presenter_obj_li
    {container_class_li}
    {display_mode}
    {link_to_type}
    {link_to_id}
    {lq__event_presenter_obj_li}
    {log_lvl}></Comp_event_presenter_obj_li>
