<script lang="ts">
/** @type {import('./$types').LayoutData} */
export let data: any;

import { goto } from '$app/navigation';
import { onMount } from 'svelte';
import type { Writable } from 'svelte/store';
import { localStorageStore } from '@skeletonlabs/skeleton';

import type { key_val } from '$lib/ae_stores';
// import { ae_util } from '$lib/ae_utils';
import { api } from '$lib/api';
import { ae_loc, ae_sess, ae_api, slct } from '$lib/ae_stores';
import { events_loc, events_slct, events_trigger } from '$lib/ae_events_stores';

// import Element_data_store from '$lib/element_data_store.svelte';

$events_loc.qry__enabled = 'enabled';
$events_loc.qry__hidden = 'not_hidden';
$events_loc.qry__limit = 15;
$events_loc.qry__offset = 0;

// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other.
$slct.account_id = data.account_id;
console.log(`$slct.account_id = `, $slct.account_id);
let ae_acct = data[$slct.account_id];
console.log(`ae_acct = `, ae_acct);

$events_slct.event_id = ae_acct.slct.event_id;
$events_slct.event_obj = ae_acct.slct.event_obj;

let ae_promises: key_val = {};


onMount(() => {
    console.log('Events - Presentation Management: +layout.svelte');
});

</script>


<svelte:head>
	<title>Events - Presentation Management - {$events_loc.title ?? 'Æ loading...'}</title>
</svelte:head>


<section
    class="submenu flex flex-row justify-center"
    class:hidden={$ae_loc.iframe}
    >

    <span class="btn-group variant-soft-secondary px-4 py-2">
    {#each Object.entries(data.submenu) as [key, item]}
        <!-- <a href="/settings/{item.slug}">{item.title}</a> -->
        <!-- class:hidden={!$ae_loc.trusted_access && item.access} -->
        {#if item.disable}
        <button
            title={item.title}
            class="hover:variant-ghost-secondary"
            class:hidden={(!$ae_loc.trusted_access && item.access === 'trusted') || (!$ae_loc.administrator_access && item.access === 'administrator' || item.hide)}
            disabled={item.disable}

            on:click={() => {
                // window.location(item.href);
                // href={item.href}
                // invalidateAll
                goto(item.href, { });
            }}
            >
            {item.name}
        </button>
        {:else}
        <a
            href={item.href}
            title={item.title}
            class="hover:variant-ghost-secondary"
            class:hidden={(!$ae_loc.trusted_access && item.access === 'trusted') || (!$ae_loc.administrator_access && item.access === 'administrator' || item.hide)}
            class:disabled={item.disable}
            >
            {item.name}
        </a>
        {/if}
    {/each}
    </span>

</section>


<slot></slot>
