<script lang="ts">
	export let data: any;
	console.log(`ae_events_badges +page data:`, data);
	// console.log(`ae_events_badges Data Params:`, data.url.searchParams.get('event_id'));

	import { onMount } from 'svelte';

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

	import Element_data_store from '$lib/elements/element_data_store_v2.svelte';
	import Element_sql_qry from '$lib/elements/element_sql_qry.svelte';
	// import Element_obj_tbl_row from '$lib/element_obj_tbl_row.svelte';

	let sql_report_qry = null;

	onMount(() => {
		console.log('Admin: +page.svelte');

		console.log('ae_ slct:', $slct);

		let href_url = window.location.href;
		// console.log(href_url);

		$ae_loc.href_url = href_url;
		// console.log(`$ae_loc.href_url = `, $ae_loc.href_url);

		// $slct_trigger = 'msg_parent';
		// ae_util.handle_url_and_message('event_id', $events_slct.event_id);
		// ae_util.handle_url_and_message('badge_id', $events_slct.badge_id);
		// if ($events_slct.badge_id) {
		//     console.log(`Got an ID. Let's show the modal!`);
		//     modalStore.trigger(modal_edit__badge_obj);
		// }
	});
</script>

<section class="ae_admin md:container h-full mx-auto">
	<h2 class="h3">Admin for {$ae_loc.account_name} ({$ae_loc.account_id})</h2>

	<h3 class="h4">Restricted Access</h3>
	<p>Accessing the admin is currently restricted</p>

	<Element_data_store
		ds_code="admin__overview"
		ds_type="html"
		for_type="event"
		for_id={$ae_loc.event_id}
		display="block"
		class_li="p-2"
	/>

	{#if $ae_loc.trusted_access}
		<div>
			<button
				type="button"
				on:click={() => {
					$ae_loc.admin.show_option = 'ae_loc_json';
				}}
				class="btn btn-md preset-tonal-primary hover:preset-tonal-primary border border-primary-500"
			>
				AE Local Storage
			</button>

			<button
				type="button"
				on:click={() => {
					$ae_loc.admin.show_option = 'event_file_list';
				}}
				class="btn btn-md preset-tonal-primary hover:preset-tonal-primary border border-primary-500"
			>
				Event File List
			</button>

			<button
				type="button"
				on:click={() => {
					$ae_loc.admin.show_option = 'event_badge_printed';
				}}
				class="btn btn-md preset-tonal-primary hover:preset-tonal-primary border border-primary-500"
			>
				Event Badge Printed
			</button>
		</div>

		{#if $ae_loc.admin?.show_option == 'ae_loc_json'}
			<h2>AE Local Storage</h2>
			<pre class="text-xs">
{JSON.stringify($ae_loc, null, 2)}
</pre>
		{/if}

		{#if $ae_loc.admin?.show_option == 'event_file_list'}
			<h2>Report SQL</h2>
			<Element_data_store
				ds_code="rpt_sql_select_event_file_list_w_url"
				ds_type="sql"
				display="block"
				class_li="p-2"
				bind:val_sql={$ae_loc.ds['rpt_sql_select_event_file_list_w_url']}
			/>

			<Element_sql_qry
				api_cfg={$ae_api}
				run_on_load={true}
				show_textarea={true}
				sql_statement={$ae_loc.ds['rpt_sql_select_event_file_list_w_url']}
				sql_data={{ event_id: $slct.event_id, base_url: $ae_api.base_url }}
				as_list={true}
			/>
		{/if}

		{#if $ae_loc.admin?.show_option == 'event_badge_printed'}
			<h2>Report SQL</h2>
			<Element_data_store
				ds_code="rpt_sql_select_event_badge_printed_by_ext_event"
				ds_type="sql"
				display="block"
				class_li="p-2"
				bind:val_sql={$ae_loc.ds['rpt_sql_select_event_badge_printed_by_ext_event']}
			/>

			<Element_sql_qry
				api_cfg={$ae_api}
				remove_breaks={false}
				run_on_load={true}
				show_textarea={true}
				sql_statement={$ae_loc.ds['rpt_sql_select_event_badge_printed_by_ext_event']}
				sql_data={{ event_id: $slct.event_id, base_url: $ae_api.base_url }}
				as_list={true}
			/>
		{/if}
		<!-- {#if $ae_loc.app_cfg.show_element__cfg_detail} -->

		<!-- {/if} -->

		{#if $ae_loc.admin?.show_element__sql_qry}
			<h2>Report</h2>

			<span>
				<!-- Setting run_on_load to false. True seems to cause a problem with it trying to render before the results have been returned. The sql_qry_result should be checked to see if it is a list of some kind. -->
				<!-- <Element_sql_qry
            api_cfg={$ae_api}
            run_on_load={false}
            show_textarea={false}
            remove_breaks={true}
            button_label={'Refresh Results'}
            sql_statement={sql_report_qry}
            sql_data={sql_report_data}
            as_list={true}
            log_lvl={1}
            /> -->
			</span>
		{/if}
	{/if}
</section>

<style lang="postcss">
</style>
