<script lang="ts">
    import Pagebuilder from "../lib/components/pagebuilder/pagebuilder.svelte"
    import { navigation, sites } from "../lib/stores"
    import NotFound from "./NotFound.svelte"
    export let path: string
    let site: Site
    function getSelectedSite(path: string): Site | {} {
        let site = {}
        console.log($sites, "sites")
        if (Object.values($sites).length == 0) return {}
        Object.values($sites).forEach((element) => {
            if (element.path == "/" + path) site = element
        })
        return site
    }
    $: {
        void $sites
        //@ts-ignore
        site = getSelectedSite(path)
    }
</script>

<svelte:head>
    {#key site}
        <!-- Title -->
        {#if site?.title}
            <title>{site.title}</title>
        {:else if site?.meta?.titel}
            <title>{site.meta.titel}</title>
        {:else}
            <title>AllKids Erfurt</title>
        {/if}

        <!-- Description -->
        {#if site?.meta?.beschreibung}
            <meta name="description" content="{site.meta.beschreibung}" />
        {/if}

        <!-- Keywords -->
        {#if site?.meta?.keywords}
            <meta name="keywords" content="{site.meta.keywords}" />
        {:else}
            <meta
                name="keywords"
                content="AllKids Erfurt, Second-Hand Kinderkleidung Erfurt, Gebrauchte Kinderspielzeuge Erfurt, AllKids Second-Hand, Erfurt Kinder Second-Hand-Shop, Kinderkleidung Erfurt, Nachhaltige Kinderprodukte Erfurt, AllKids Kinderladen, Second-Hand Babyausstattung Erfurt, AllKids Kleidung Tausch, Erfurt Second-Hand Kinderbücher, AllKids ökologisch, Kinder Second-Hand Markt Erfurt, Günstige Kinderkleidung Erfurt, AllKids Bewertungen, Kinderartikel Kauf und Verkauf Erfurt, Second-Hand Kinderwagen Erfurt, AllKids nachhaltiger Laden, Gebrauchte Kindermöbel Erfurt, AllKids Erfurt Standort"
            />
        {/if}

        {#if site?.aktiv === false}
            <meta name="robots" content="noindex" />
        {/if}
    {/key}
</svelte:head>
<main class="">
    {#if site != undefined}
        {#each site.row || [] as row, i}
            <Pagebuilder rowNr="{i}" row="{row}" rows="{site?.row}" siteId="{site?.id}" />
        {/each}
    {:else if site === undefined}
        <NotFound />
    {/if}
</main>

<style lang="less">
    main {
        min-height: 70vh;
        width: 100%;
        padding: 0px min(4.5vw, 100px);
        display: flex;
        flex-direction: column;
        align-items: center;
    }
</style>
