<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.
    }

    let { lq__event_presenter_obj }: 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_loc,
        events_sess,
        events_slct,
        events_trigger
    } from '$lib/stores/ae_events_stores';
    // import { events_func } from '$lib/ae_events_functions';

    import Event_launcher_file_cont from './launcher_file_cont.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'}
        <span class="fas fa-user"></span>
        {lq__event_presenter_obj?.full_name}
    {:else if lq__event_presenter_obj?.given_name == 'Group'}
        <span class="fas fa-users"></span>
        {lq__event_presenter_obj?.affiliations}
    {:else}
        --not set--
    {/if}
</strong>

{#if !lq__event_presenter_obj?.file_count}
    <p class="text-sm text-center 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-xs text-surface-600-400">
                <strong>
                    <span class="fas fa-file-archive"></span>
                    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}
                <li
                    class="flex flex-col md:flex-row flex-wrap gap-1 items-center justify-start"
                    class:hidden={!$events_loc.launcher
                        .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:hide_draft={
                            $events_loc.launcher.hide_content__draft_files
                        }
                        show_bak_download={$ae_loc.trusted_access}
                        session_type={event_file_obj?.event_session_type_code ??
                            'oral'}
                        open_method={event_file_obj?.event_session_type_code ==
                        '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}
