<script lang="ts">
    interface Props {
        lq__event_presentation_obj: any;
    }

    let { lq__event_presentation_obj }: Props = $props();

    import { liveQuery } from 'dexie';
    import { db_events } from '$lib/ae_events/db_events';
    import { ae_loc } from '$lib/stores/ae_stores';
    import { events_loc, events_sess } from '$lib/stores/ae_events_stores';
    import Event_launcher_file_cont from './launcher_file_cont.svelte';

    // Event File (Directly linked to presentation)
    let lq__event_file_obj_li = $derived(
        liveQuery(async () => {
            if (!lq__event_presentation_obj?.event_presentation_id) return [];
            let results = await db_events.file
                .where('for_id')
                .equals(lq__event_presentation_obj.event_presentation_id)
                .reverse()
                .sortBy('created_on');
            return results;
        })
    );
</script>

{#if $lq__event_file_obj_li && $lq__event_file_obj_li.length}
    <section class="event_presentation_file_list my-1">
        <div class="text-[10px] text-surface-600-400 uppercase font-bold tracking-wider opacity-70">
            Presentation Files:
        </div>
        <ul class="space-y-1">
            {#each $lq__event_file_obj_li as event_file_obj}
                <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_presentation_obj?.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}
