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

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

import { Modal } from 'flowbite-svelte';
import { Eye, EyeOff, Info, Settings, X } from '@lucide/svelte';

import { ae_loc } from '$lib/stores/ae_stores';
import { events_slct } from '$lib/stores/ae_events_stores';
import { pres_mgmt_loc } from '$lib/stores/ae_events_stores__pres_mgmt.svelte';

import Element_data_store from '$lib/elements/element_data_store.svelte';
import Comp__events_menu_nav from '../../../ae_comp__events_menu_nav.svelte';

let show_modal = $state(false);
let show_help = $state(false);
</script>

<div class="pres_mgmt__event_reports ae_container_module_menu">
    <div
        class="flex w-full flex-row flex-wrap items-center justify-around gap-1">
        <Comp__events_menu_nav
            hide={!$ae_loc.authenticated_access}
            event_id={$lq__event_obj?.event_id}
            ae_core={$ae_loc.edit_mode && $ae_loc.manager_access}
            events__locations={$ae_loc.trusted_access}
            events__session_search={$events_slct.event_id} />

        <span
            class="ae_menu__object_options flex flex-row flex-wrap items-center justify-around gap-0.5">
            <!-- Options modal trigger -->
            {#if $ae_loc.trusted_access}
                <button
                    type="button"
                    onclick={() => (show_modal = true)}
                    class="btn btn-sm ae_btn_info"
                    title="Report options">
                    <Settings size="1em" class="mr-1" />
                    Options
                </button>
            {/if}

            <!-- Help toggle -->
            <button
                type="button"
                onclick={() => (show_help = !show_help)}
                class="btn btn-sm"
                class:ae_btn_info_filled={show_help}
                class:ae_btn_info={!show_help}
                title="Help and information about the reports">
                <Info size="1em" class="mr-1" />
                {show_help ? 'Hide Help' : 'Help'}
            </button>
        </span>
    </div>

    <!-- Options Modal -->
    <Modal
        bind:open={show_modal}
        autoclose={false}
        dismissable={true}
        placement="top-center"
        size="md"
        class="relative mx-auto flex w-full flex-col rounded-lg bg-white text-gray-800 shadow-xl dark:bg-gray-800 dark:text-gray-200"
        headerClass="flex flex-row gap-2 items-center justify-between w-full bg-surface-100 dark:bg-surface-800 p-4 rounded-t-lg border-b border-surface-200 dark:border-surface-700">
        {#snippet header()}
            <h3 class="flex flex-1 items-center gap-2 text-base font-bold">
                <Settings size="1.1em" class="text-primary-500" />
                Report Options
            </h3>
            <button
                type="button"
                class="btn-icon btn-icon-sm preset-tonal-surface ml-2"
                onclick={() => (show_modal = false)}>
                <X size="1.1em" />
            </button>
        {/snippet}

        <div class="flex flex-col gap-4 p-4">
            <!-- Query limits -->
            {#if $ae_loc.authenticated_access}
                <section>
                    <h4
                        class="text-surface-500 mb-2 text-xs font-semibold tracking-wider uppercase">
                        Query Limits
                    </h4>
                    <div class="flex flex-col gap-2">
                        <span class="flex flex-row items-center gap-2">
                            <label
                                class="w-32 text-right text-sm"
                                for="qry_limit__presenters"
                                >Max presenters:</label>
                            <select
                                id="qry_limit__presenters"
                                bind:value={
                                    pres_mgmt_loc.current.qry_limit__presenters
                                }
                                class="select w-20 text-sm">
                                <option value={25}>25</option>
                                <option value={50}>50</option>
                                <option value={75}>75</option>
                                <option value={100}>100</option>
                                <option value={150}>150</option>
                                <option value={200}>200</option>
                                <option value={250}>250</option>
                                <option value={300}>300</option>
                                <option value={500}>500</option>
                                <option value={750}>750</option>
                                <option value={1000}>1000</option>
                            </select>
                        </span>

                        <span class="flex flex-row items-center gap-2">
                            <label
                                class="w-32 text-right text-sm"
                                for="qry_limit__sessions">Max sessions:</label>
                            <select
                                id="qry_limit__sessions"
                                bind:value={
                                    pres_mgmt_loc.current.qry_limit__sessions
                                }
                                class="select w-20 text-sm">
                                <option value={25}>25</option>
                                <option value={50}>50</option>
                                <option value={75}>75</option>
                                <option value={100}>100</option>
                                <option value={200}>200</option>
                                <option value={500}>500</option>
                            </select>
                        </span>

                        <span class="flex flex-row items-center gap-2">
                            <label
                                class="w-32 text-right text-sm"
                                for="qry_limit__files">Max files:</label>
                            <select
                                id="qry_limit__files"
                                bind:value={
                                    pres_mgmt_loc.current.qry_limit__files
                                }
                                class="select w-20 text-sm">
                                <option value={25}>25</option>
                                <option value={50}>50</option>
                                <option value={75}>75</option>
                                <option value={100}>100</option>
                                <option value={200}>200</option>
                                <option value={500}>500</option>
                            </select>
                        </span>
                    </div>
                </section>

                <!-- Visibility filters -->
                <section>
                    <h4
                        class="text-surface-500 mb-2 text-xs font-semibold tracking-wider uppercase">
                        Filters
                    </h4>
                    <div class="flex flex-col gap-1">
                        <button
                            type="button"
                            onclick={() => {
                                pres_mgmt_loc.current.show__direct_download =
                                    !pres_mgmt_loc.current.show__direct_download;
                            }}
                            class="btn btn-sm w-full justify-between"
                            class:preset-tonal-success={pres_mgmt_loc.current.show__direct_download}
                            class:preset-tonal-warning={!pres_mgmt_loc.current.show__direct_download}>
                            {#if pres_mgmt_loc.current.show__direct_download}<EyeOff
                                    size="1em"
                                    class="mr-1" />{:else}<Eye
                                    size="1em"
                                    class="mr-1" />{/if}
                            {pres_mgmt_loc.current.show__direct_download
                                ? 'Hide Download Buttons?'
                                : 'Show Download Buttons?'}
                        </button>

                        <button
                            type="button"
                            onclick={() => {
                                pres_mgmt_loc.current.qry_hidden =
                                    pres_mgmt_loc.current.qry_hidden === 'all'
                                        ? 'not_hidden'
                                        : 'all';
                            }}
                            class="btn btn-sm w-full justify-between"
                            class:preset-tonal-success={pres_mgmt_loc.current.qry_hidden === 'all'}
                            class:preset-tonal-warning={pres_mgmt_loc.current.qry_hidden !== 'all'}>
                            {#if pres_mgmt_loc.current.qry_hidden === 'all'}<EyeOff
                                    size="1em"
                                    class="mr-1" />{:else}<Eye
                                    size="1em"
                                    class="mr-1" />{/if}
                            {pres_mgmt_loc.current.qry_hidden === 'all'
                                ? 'Hide Hidden Sessions?'
                                : 'Show Hidden Sessions?'}
                        </button>

                        {#if $ae_loc.manager_access}
                            <button
                                type="button"
                                onclick={() => {
                                    pres_mgmt_loc.current.qry_enabled =
                                        pres_mgmt_loc.current.qry_enabled ===
                                        'all'
                                            ? 'enabled'
                                            : 'all';
                                }}
                                class="btn btn-sm w-full justify-between"
                                class:preset-tonal-success={pres_mgmt_loc.current.qry_enabled === 'all'}
                                class:preset-tonal-warning={pres_mgmt_loc.current.qry_enabled !== 'all'}>
                                {#if pres_mgmt_loc.current.qry_enabled === 'all'}<EyeOff
                                        size="1em"
                                        class="mr-1" />{:else}<Eye
                                        size="1em"
                                        class="mr-1" />{/if}
                                {pres_mgmt_loc.current.qry_enabled === 'all'
                                    ? 'Hide Disabled Sessions?'
                                    : 'Show Disabled Sessions?'}
                            </button>
                        {/if}
                    </div>
                </section>
            {/if}
        </div>
    </Modal>

    <!-- Help panel -->
    <Element_data_store
        ds_code="events__pres_mgmt__reports_help"
        ds_name="Default: Events - Pres Mgmt Event Reports Help"
        ds_type="html"
        for_type="event"
        for_id={$events_slct.event_id}
        class_li="ae_container_module_help"
        show_edit={false}
        show_edit_btn={true}
        hide={!show_help} />
</div>
