<script lang="ts">
import {
    ae_snip,
    ae_loc,
    ae_sess,
    ae_api,
    ae_trig,
    slct,
    slct_trigger
} from '$lib/stores/ae_stores';
import {
    TrendingUp,
    MapPin,
    Wrench,
    Search,
    GraduationCap,
    Plane,
    Presentation,
    Settings
} from '@lucide/svelte';

interface Props {
    // import { events_loc, events_sess, events_slct, events_trigger, events_trig_kv } from '$lib/stores/ae_events_stores';
    hide?: boolean;
    event_id?: null | string;
    ae_core?: boolean;
    events__launcher_id?: null | string; // event_location_id
    events__location_id?: null | string; // event_location_id
    events__locations?: boolean; // event_id
    // export let events__presenter_id: null|string = null; // event_presenter_id
    events__reports?: boolean; // event_id
    events__settings?: boolean; // event_id
    events__launcher_session_id?: null | string; // event_session_id to pass to launcher as ?session_id=
    events__session_id?: null | string; // event_session_id — used for "Back to Session" link only
    events__session_search?: boolean; // event_id
    events__launcher_extra_params?: string; // extra URL params appended to the launcher link (e.g. 'iframe=true&launcher_menu=hide')
}

let {
    hide = true,
    event_id = null,
    ae_core = false,
    events__launcher_id = null,
    events__launcher_session_id = null,
    events__launcher_extra_params = '',
    events__location_id = null,
    events__locations = false,
    events__reports = false,
    events__settings = false,
    events__session_id = null,
    events__session_search = false
}: Props = $props();

// Build launcher URL segments separately so the href template stays simple (avoids ternaries in href attr)
let launcher_loc_seg = $derived(
    events__launcher_id ? `/${events__launcher_id}` : ''
);
let launcher_sess_qry = $derived.by(() => {
    const parts: string[] = [];
    if (events__launcher_session_id)
        parts.push(`session_id=${events__launcher_session_id}`);
    if (events__launcher_extra_params)
        parts.push(events__launcher_extra_params);
    return parts.length ? `?${parts.join('&')}` : '';
});
</script>

<!-- This is for common navigation links. -->
<div
    class="ae_comp__events_menu_nav flex w-full flex-row flex-wrap items-center justify-between gap-1.5"
    class:hidden={hide}>
    <span
        class="ae_menu__navigation_options flex flex-row flex-wrap items-center justify-around gap-0.5">
        {#if $ae_loc.trusted_access && $ae_loc.edit_mode}
        <a
            href="/core"
            class="btn btn-sm ae_btn_warning mx-1"
            class:hidden={!ae_core}>
            <Settings size="1em" aria-hidden="true" />
            Æ Core
        </a>
        {/if}

        {#if $ae_loc.public_access && $ae_loc.edit_mode}
        <a
            href="/events/{event_id}/reports"
            class="btn btn-sm ae_btn_info mx-1"
            class:hidden={!events__reports}>
            <TrendingUp size="1em" aria-hidden="true" />
            Pres Mgmt Reports
        </a>
        {/if}
        {#if $ae_loc.administrator_access || ($ae_loc.trusted_access && $ae_loc.edit_mode)}
        <a
            href="/events/{event_id}/locations"
            class="btn btn-sm ae_btn_info mx-1"
            class:hidden={!events__locations}>
            <MapPin size="1em" aria-hidden="true" />
            Locations
        </a>
        {/if}
        <a
            href="/events/{event_id}/settings"
            class="btn btn-sm ae_btn_warning mx-1"
            class:hidden={!events__settings}>
            <Wrench size="1em" aria-hidden="true" />
            Admin Tools
        </a>
    </span>

    <span
        class="ae_menu__navigation_options flex flex-row flex-wrap items-center justify-around gap-0.5 grow">
        <a
            href="/events/{event_id}/pres_mgmt"
            class="btn btn-sm ae_btn_info mx-1"
            class:hidden={!events__session_search}>
            <Search size="1em" aria-hidden="true" />
            Session Search
        </a>
        <a
            href="/events/{event_id}/session/{events__session_id}"
            class="btn btn-sm ae_btn_info mx-1"
            class:hidden={!events__session_id}>
            <Presentation size="1em" aria-hidden="true" />
            Back to Session
        </a>

        {#if $ae_loc.administrator_access || ($ae_loc.trusted_access && $ae_loc.edit_mode)}
        <a
            href="/events/{event_id}/launcher{launcher_loc_seg}{launcher_sess_qry}"
            class="btn btn-sm ae_btn_info mx-1"
            class:hidden={!event_id}>
            <Plane size="1em" aria-hidden="true" />
            Launcher
        </a>
        {/if}
        {#if $ae_loc.trusted_access}
        <a
            href="/events/{event_id}/location/{events__location_id}"
            class="btn btn-sm ae_btn_info mx-1"
            class:hidden={!events__location_id}>
            <MapPin size="1em" aria-hidden="true" />
            Session Location
        </a>
        {/if}
    </span>
</div>
