<script lang="ts">
    import { page } from '$app/state';
    import { onMount } from 'svelte';
    import Embedding from '$lib/components/embedding/Embedding.svelte';
    import {
        getMergedEmbeddingOptions,
        type EmbeddingOptions,
    } from '$lib/components/embedding/embedding';

    let embeddingOptions: EmbeddingOptions | undefined = undefined;

    onMount(() => {
        let options = page.url.searchParams.get('options');
        if (options === null) {
            return;
        }
        options = JSON.parse(options);
        if (options === null) {
            return;
        }
        embeddingOptions = getMergedEmbeddingOptions(options);
        if (embeddingOptions.key === '' && embeddingOptions.basemap === 'satellite') {
            embeddingOptions.basemap = 'libertyTopo';
        }
    });
</script>

{#if embeddingOptions}
    <Embedding options={embeddingOptions} hash={page.url.hash} />
{/if}
