<script lang="ts">
interface Props {
    // export let slct_event_presenter_id: string;
    lq__event_presenter_obj: any; // This is not actually the LiveQuery object. This was pulled from the list of presenters for a presentation. With Svelte 5 this should not matter.
    session_type?: string;
}

let { lq__event_presenter_obj, session_type = 'oral' }: Props = $props();

import type { key_val } from '$lib/stores/ae_stores';
// import { ae_util } from '$lib/ae_utils/ae_utils';
// import { api } from '$lib/api';

import { liveQuery } from 'dexie';

import {
    ae_snip,
    ae_loc,
    ae_sess,
    ae_api,
    ae_trig,
    slct,
    slct_trigger
} from '$lib/stores/ae_stores';
import { db_events } from '$lib/ae_events/db_events';
import {
    events_sess,
    events_slct,
    events_trigger
} from '$lib/stores/ae_events_stores';
import { launcher_loc } from '$lib/stores/ae_events_stores__launcher.svelte';
// import { events_func } from '$lib/ae_events/ae_events_functions';

import Event_launcher_file_cont from './launcher_file_cont.svelte';
import { Archive, User, Users } from '@lucide/svelte';
// export let slct_event_presentation_id: string;

let ae_promises: key_val = {
    get_li__event_file: null
};

// Event File
let lq__event_file_obj_li = $derived(
    liveQuery(async () => {
        let results = await db_events.file
            // .where('event_session_id')
            .where('for_id')
            .equals(lq__event_presenter_obj?.event_presenter_id)
            .reverse()
            .sortBy('created_on');
        return results;
    })
);
</script>

<strong>
    {#if lq__event_presenter_obj?.given_name && lq__event_presenter_obj?.given_name != 'Group'}
        <User size="0.85em" class="inline" />
        {lq__event_presenter_obj?.full_name}
    {:else if lq__event_presenter_obj?.given_name == 'Group'}
        <Users size="0.85em" class="inline" />
        {lq__event_presenter_obj?.affiliations}
    {:else}
        --not set--
    {/if}
</strong>

{#if !lq__event_presenter_obj?.file_count}
    <p class="text-center text-sm text-gray-400">
        <!-- <span class="fas fa-exclamation"></span> -->
        No files to show for this presenter at this time.
        <!-- <span class="fas fa-exclamation"></span> -->
    </p>
{/if}

{#if $lq__event_file_obj_li && $lq__event_file_obj_li.length}
    <section class="event_session_file_list">
        <div>
            <div class="text-surface-600-400 text-xs">
                <strong>
                    <Archive size="1em" class="inline" />
                    Presenter Files:
                    {#if $ae_loc.administrator_access && $ae_loc.edit_mode}
                        ({$lq__event_file_obj_li?.length}&times;)
                    {/if}
                </strong>
            </div>
        </div>
        <ul class="space-y-1">
            {#each $lq__event_file_obj_li as event_file_obj, index (event_file_obj.event_file_id)}
                <li
                    class="flex flex-col flex-wrap items-center justify-start gap-1 md:flex-row"
                    class:hidden={!launcher_loc.current
                        .show_content__hidden_files && event_file_obj.hide}>
                    <Event_launcher_file_cont
                        event_file_id={event_file_obj.event_file_id}
                        {event_file_obj}
                        hide_created_on={false}
                        bind:show_internal_purpose_files={
                            launcher_loc.current.show_content__internal_files
                        }
                        show_bak_download={$ae_loc.trusted_access}
                        session_type={session_type || 'oral'}
                        open_method={session_type == 'poster' ? 'modal' : null}
                        modal_title={lq__event_presenter_obj?.event_presentation_name}
                        bind:modal__title={$events_sess.launcher.modal__title}
                        bind:modal__open_event_file_id={
                            $events_sess.launcher.modal__open_event_file_id
                        }
                        bind:modal__event_file_obj={
                            $events_sess.launcher.modal__event_file_obj
                        } />
                </li>
            {/each}
        </ul>
    </section>
{/if}
