<script lang="ts">
    export interface Props {
        data?: any;
        log_lvl?: number;
        // export let event_location_id: string;
        lq__event_obj: any;
        lq__event_location_obj: any;
    }

    let {
        data = null,
        log_lvl = 0,
        lq__event_obj,
        lq__event_location_obj
    }: Props = $props();

    import {
        ae_snip,
        ae_loc,
        ae_sess,
        ae_api,
        ae_trig,
        slct,
        slct_trigger
    } from '$lib/stores/ae_stores';
    import {
        events_loc,
        events_sess,
        events_slct,
        events_trigger,
        events_trig_kv
    } from '$lib/stores/ae_events_stores';
    import { events_func } from '$lib/ae_events_functions';

    import { api } from '$lib/api/api';
    import Element_data_store from '$lib/elements/element_data_store_v3.svelte';
    import Comp__events_menu_nav from '../../../../ae_comp__events_menu_nav.svelte';

</script>

<!-- New standard page specific menu 2025-06-20 -->
<div class="pres_mgmt__location_menu ae_container_module_menu">
    <!-- BEGIN: The menu button options -->
    <div
        class="flex flex-row flex-wrap gap-1 items-center justify-around w-full"
    >
        <Comp__events_menu_nav
            hide={!$ae_loc.authenticated_access}
            event_id={$lq__event_obj?.event_id}
            ae_core={$ae_loc.administrator_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"
        >
            <!-- Button to toggle between the regular location view and managing location files -->
            <button
                type="button"
                onclick={() => {
                    if (
                        $events_loc.pres_mgmt.show_content__location_view ==
                        'manage_files'
                    ) {
                        $events_loc.pres_mgmt.show_content__location_view =
                            null;
                    } else {
                        $events_loc.pres_mgmt.show_content__location_view =
                            'manage_files';
                    }
                }}
                class={ae_snip.classes__events_pres_mgmt_menu__button_special}
                class:preset-filled-primary-500={$events_loc.pres_mgmt
                    .show_content__location_view == 'manage_files'}
                class:preset-tonal-primary={$events_loc.pres_mgmt
                    .show_content__location_view != 'manage_files'}
                class:hidden={!$ae_loc.trusted_access || 1 == 1}
                title="Manage files for the location"
            >
                {#if $events_loc.pres_mgmt.show_content__location_view == 'manage_files'}
                    <span class="fas fa-users m-1"></span>
                    <!-- View Details -->
                    Location Sessions?
                {:else}
                    <span class="fas fa-file-archive m-1"></span>
                    Location Files?
                    <span
                        class="badge badge-icon preset-tonal-success absolute -top-1.5 -right-1.5 z-10"
                        class:hidden={!$lq__event_location_obj?.file_count}
                    >
                        {$lq__event_location_obj?.file_count}×
                    </span>
                {/if}
            </button>

            <button
                type="button"
                onclick={() => {
                    if (
                        $events_loc.pres_mgmt.show_menu__location == 'options'
                    ) {
                        $events_loc.pres_mgmt.show_menu__location = null;
                    } else {
                        $events_loc.pres_mgmt.show_menu__location = 'options';
                    }
                }}
                class="btn btn-sm mx-1"
                class:ae_btn_info_filled={$events_loc.pres_mgmt
                    .show_menu__location == 'options'}
                class:ae_btn_info={$events_loc.pres_mgmt.show_menu__location !=
                    'options'}
                class:hidden={!$ae_loc.trusted_access}
                title="Options for the location"
            >
                <span class="fas fa-cog m-1"></span>
                {#if $events_loc.pres_mgmt.show_menu__location == 'options'}
                    Hide
                {:else}
                    Show
                {/if}
                Options?
            </button>

            <button
                type="button"
                onclick={() => {
                    if ($events_loc.pres_mgmt.show_menu__location == 'help') {
                        $events_loc.pres_mgmt.show_menu__location = null;
                    } else {
                        $events_loc.pres_mgmt.show_menu__location = 'help';
                    }
                }}
                class="btn btn-sm mx-1"
                class:ae_btn_info_filled={$events_loc.pres_mgmt
                    .show_menu__location == 'help'}
                class:ae_btn_info={$events_loc.pres_mgmt.show_menu__location !=
                    'help'}
                title="Help and information about the location"
            >
                <span class="fas fa-question-circle m-1"></span>
                {#if $events_loc.pres_mgmt.show_menu__location == 'help'}
                    Hide Help?
                {:else}
                    Help?
                {/if}
            </button>
        </span>

        <!-- <span
        class="ae_menu__action_options"
        class:hidden={!$ae_loc.administrator_access}
        >
        No Actions
    </span> -->
    </div>
    <!-- END: The menu button options -->

    <!-- BEGIN: The expanded menu area for information and options -->
    <div
        class:ae_container_module_options={$events_loc.pres_mgmt
            .show_menu__location == 'options'}
        class:hidden={$events_loc.pres_mgmt.show_menu__location != 'options'}
    >
        <button
            type="button"
            onclick={async () => {
                await api.update_ae_obj_v3({ api_cfg: $ae_api, obj_type: 'event_location', obj_id: $lq__event_location_obj?.event_location_id, fields: { priority: !$lq__event_location_obj?.priority } });
                events_func.load_ae_obj_id__event_location({ api_cfg: $ae_api, event_location_id: $lq__event_location_obj?.event_location_id, log_lvl });
            }}
            class="btn btn-sm m-1 *:hover:inline"
            class:ae_btn_surface_outlined={!$lq__event_location_obj?.priority}
            class:ae_btn_success={$lq__event_location_obj?.priority}
        >
            {#if $lq__event_location_obj?.priority}
                <span class="fas fa-star m-1"></span>
                <span class="hidden"> Not Priority? </span>
            {:else}
                <span class="far fa-star m-1"></span>
                <span class="hidden"> Priority </span>
                ?
            {/if}
        </button>

        <button
            type="button"
            onclick={async () => {
                await api.update_ae_obj_v3({ api_cfg: $ae_api, obj_type: 'event_location', obj_id: $lq__event_location_obj?.event_location_id, fields: { hide: !$lq__event_location_obj?.hide } });
                events_func.load_ae_obj_id__event_location({ api_cfg: $ae_api, event_location_id: $lq__event_location_obj?.event_location_id, log_lvl });
            }}
            class="btn btn-sm m-1 *:hover:inline"
            class:ae_btn_success_outlined={!$lq__event_location_obj?.hide}
            class:ae_btn_warning={$lq__event_location_obj?.hide}
            disabled={!$ae_loc.trusted_access}
        >
            {#if $lq__event_location_obj?.hide}
                <span class="fas fa-toggle-on m-1"></span>
                Unhide?
            {:else}
                <span class="fas fa-eye m-1"></span>
                <span class="hidden"> Not Hidden </span>
            {/if}
        </button>

        <!-- Enable/Disable -->
        <button
            type="button"
            onclick={async () => {
                await api.update_ae_obj_v3({ api_cfg: $ae_api, obj_type: 'event_location', obj_id: $lq__event_location_obj?.event_location_id, fields: { enable: !$lq__event_location_obj?.enable } });
                events_func.load_ae_obj_id__event_location({ api_cfg: $ae_api, event_location_id: $lq__event_location_obj?.event_location_id, log_lvl });
            }}
            class="btn btn-sm"
            class:ae_btn_success_outlined={$lq__event_location_obj?.enable}
            class:ae_btn_error={!$lq__event_location_obj?.enable}
            disabled={!$ae_loc.manager_access}
        >
            {#if $lq__event_location_obj?.enable}
                <span class="fas fa-toggle-on m-1"></span>
                Enabled
            {:else}
                <span class="fas fa-toggle-off m-1"></span>
                Enable?
            {/if}
        </button>

        <!-- Sort -->

        <!-- Group -->

        {#if $ae_loc.administrator_access}
            <div class="flex flex-col gap-1 items-center">
                <!-- {#if $events_loc.pres_mgmt.show_content__location_qr}
                <button type="button"
                    disabled={!$ae_loc.manager_access}
                    on:click={() => {
                        $events_loc.pres_mgmt.show_content__location_qr = false;
                    }}
                    class="btn btn-sm variant-ghost-success"
                    >
                    <span class="fas fa-toggle-on m-1"></span>
                    Showing QR Code
                </button>
            {:else}
                <button type="button"
                    disabled={!$ae_loc.manager_access}
                    on:click={() => {
                        $events_loc.pres_mgmt.show_content__location_qr = true;
                    }}
                    class="btn btn-sm variant-ringed-warning"
                    >
                    <span class="fas fa-toggle-off m-1"></span>
                    Show QR Code?
                </button>
            {/if} -->

                <!-- Show/Hide launcher links (new version) -->
                <button
                    type="button"
                    onclick={() => {
                        $events_loc.pres_mgmt.hide__launcher_link =
                            !$events_loc.pres_mgmt.hide__launcher_link;
                    }}
                    class="btn btn-sm ae_btn_surface justify-between w-full text-center"
                >
                    <span
                        class="fas {$events_loc.pres_mgmt.hide__launcher_link
                            ? 'fa-toggle-off'
                            : 'fa-toggle-on'} m-1"
                    ></span>
                    <span class="grow">
                        <span class="fas fa-plane m-1"></span>
                        {$events_loc.pres_mgmt.hide__launcher_link
                            ? 'Show Launcher Links'
                            : 'Hide Launcher Links?'}
                    </span>
                </button>

                <!-- Show/Hide launcher links (legacy version) -->
                <button
                    type="button"
                    onclick={() => {
                        $events_loc.pres_mgmt.hide__launcher_link_legacy =
                            !$events_loc.pres_mgmt.hide__launcher_link_legacy;
                    }}
                    class="btn btn-sm ae_btn_surface justify-between w-full text-center"
                >
                    <span
                        class="fas {$events_loc.pres_mgmt
                            .hide__launcher_link_legacy
                            ? 'fa-toggle-off'
                            : 'fa-toggle-on'} m-1"
                    ></span>
                    <span class="grow">
                        <span class="fas fa-paper-plane m-1"></span>
                        {$events_loc.pres_mgmt.hide__launcher_link_legacy
                            ? 'Show Launcher Links'
                            : 'Hide Legacy Launcher Links?'}
                    </span>
                </button>

                <!-- Show/Hide links to the location (room) -->
                <button
                    type="button"
                    onclick={() => {
                        $events_loc.pres_mgmt.hide__location_link =
                            !$events_loc.pres_mgmt.hide__location_link;
                    }}
                    class="btn btn-sm ae_btn_surface justify-between w-full text-center"
                >
                    <span
                        class="fas {$events_loc.pres_mgmt.hide__location_link
                            ? 'fa-toggle-off'
                            : 'fa-toggle-on'} m-1"
                    ></span>
                    <span class="grow">
                        <span class="fas fa-map-marker-alt m-1"></span>
                        {$events_loc.pres_mgmt.hide__location_link
                            ? 'Show Location Links'
                            : 'Hide Location Links?'}
                    </span>
                </button>

                {#if $events_loc.pres_mgmt.show_content__session_files}
                    <button
                        type="button"
                        disabled={!$ae_loc.manager_access}
                        onclick={() => {
                            $events_loc.pres_mgmt.show_content__session_files = false;
                        }}
                        class="btn btn-sm ae_btn_surface justify-between w-full text-center"
                    >
                        <span class="fas fa-toggle-on m-1"></span>
                        <span class="grow">
                            <span class="fas fa-list m-1"></span>
                            Hide Linked Files (testing)
                        </span>
                    </button>
                {:else}
                    <button
                        type="button"
                        disabled={!$ae_loc.manager_access}
                        onclick={() => {
                            $events_loc.pres_mgmt.show_content__session_files = true;
                        }}
                        class="btn btn-sm ae_btn_surface_outlined justify-between w-full text-center"
                    >
                        <span class="fas fa-toggle-off m-1"></span>
                        <span class="grow">
                            <span class="fas fa-list m-1"></span>
                            Show Linked Files? (testing)
                        </span>
                    </button>
                {/if}

                {#if $events_loc.pres_mgmt.show_content__session_presentations}
                    <button
                        type="button"
                        disabled={!$ae_loc.manager_access}
                        onclick={() => {
                            $events_loc.pres_mgmt.show_content__session_presentations = false;
                        }}
                        class="btn btn-sm ae_btn_surface justify-between w-full text-center"
                    >
                        <span class="fas fa-toggle-on m-1"></span>
                        <span class="grow">
                            <span class="fas fa-list m-1"></span>
                            Hide Linked Presentations (testing)
                        </span>
                    </button>
                {:else}
                    <button
                        type="button"
                        disabled={!$ae_loc.manager_access}
                        onclick={() => {
                            $events_loc.pres_mgmt.show_content__session_presentations = true;
                        }}
                        class="btn btn-sm ae_btn_surface_outlined justify-between w-full text-center"
                    >
                        <span class="fas fa-toggle-off m-1"></span>
                        <span class="grow">
                            <span class="fas fa-list m-1"></span>
                            Show Linked Presentations? (testing)
                        </span>
                    </button>
                {/if}
            </div>
        {/if}

        {#if $ae_loc?.trusted_access}
            <div
                class="flex flex-row flex-wrap gap-1 items-center justify-evenly max-w-56"
            >
                {#if $ae_loc?.edit_mode}
                    <button
                        type="button"
                        onclick={() => {
                            $ae_loc.edit_mode = false;
                        }}
                        class="btn btn-sm ae_btn_warning justify-between w-full text-center"
                        title="Turn off edit mode"
                    >
                        <span class="fas fa-toggle-on m-1"></span>
                        <span class="grow">
                            <span class="fas fa-edit m-1"></span>
                            Edit Mode Off
                        </span>
                    </button>
                {:else}
                    <button
                        type="button"
                        onclick={() => {
                            $ae_loc.edit_mode = true;
                        }}
                        class="btn btn-sm ae_btn_warning_outlined justify-between w-full text-center"
                        title="Turn on edit mode"
                    >
                        <span class="fas fa-toggle-off m-1"></span>
                        <span class="grow">
                            <span class="fas fa-user-ninja m-1"></span>
                            Edit Mode?
                        </span>
                    </button>
                {/if}

                {#if $ae_loc?.adv_mode}
                    <button
                        type="button"
                        onclick={() => {
                            $ae_loc.adv_mode = false;
                        }}
                        class="btn btn-sm ae_btn_warning justify-between w-full text-center"
                        title="Turn off advanced mode"
                    >
                        <span class="fas fa-toggle-on m-1"></span>
                        <span class="grow">
                            <span class="fas fa-magic m-1"></span>
                            Advanced Mode Off
                        </span>
                    </button>
                {:else}
                    <button
                        type="button"
                        onclick={() => {
                            $ae_loc.adv_mode = true;
                        }}
                        class="btn btn-sm ae_btn_warning_outlined justify-between w-full text-center"
                        title="Turn on advanced mode"
                    >
                        <span class="fas fa-toggle-off m-1"></span>
                        <span class="grow">
                            <span class="fas fa-hat-wizard m-1"></span>
                            Advanced Mode?
                        </span>
                    </button>
                {/if}
            </div>
        {/if}
    </div>
    <!-- END: The expanded menu area for information and options -->

    <Element_data_store
        ds_code="events__pres_mgmt__location_help"
        ds_name="Default: Events - Pres Mgmt Location Help"
        ds_type="html"
        for_type="event"
        for_id={$lq__event_location_obj?.event_id}
        class_li="ae_container_module_help"
        show_edit={false}
        show_edit_btn={true}
        hide={$events_loc.pres_mgmt.show_menu__location != 'help'}
    />

    <div>
        <button
            type="button"
            onclick={() => {
                $events_loc.pres_mgmt.show_menu__location =
                    !$events_loc.pres_mgmt.show_menu__location;
            }}
            class="btn btn-sm mx-1 ae_btn_info_filled"
            class:hidden={!$events_loc.pres_mgmt.show_menu__location}
            title="Collapse the expanded menu"
        >
            <span class="fas fa-chevron-up m-1"></span>
            {#if $events_loc.pres_mgmt.show_menu__location}
                Hide
                <!-- Collapse -->
            {:else}
                Show
            {/if}
            <!-- Menu? -->
        </button>
    </div>
</div>
<!-- End of the new standard page specific menu -->
