<script lang="ts">
    import OpenGraph from "./OpenGraph.svelte"
    import Product from "./Product.svelte"
    import SchemaOrg from "./SchemaORG.svelte"
    import { websiteName } from "../../../../config"

    export let article: boolean = false,
        createdAt: Date = null,
        updatedAt: Date = null,
        keywords: string = "",
        metaDescription: string = "",
        title: string = "",
        product: BKDFProduct = null,
        noIndex = false,
        active = true,
        FAQ = false,
        FAQDetails: {
            question: string
            answer: string
        }[] = []

    let pageTitle: string
    keywords += ", BinKrassDuFass, BKDF, BinKrassDuFass.de"

    if (title) pageTitle = `${title} - ${websiteName}`
    else pageTitle = `${websiteName}`

    const openGraphProps = {
        article,
        datePublished: createdAt,
        lastUpdated: updatedAt,
        metaDescription,
        pageTitle,
        product,
    }
    const schemaOrgProps = {
        createdAt,
        updatedAt,
        article,
        description: metaDescription,
        title: pageTitle,
        product,
        FAQ,
        FAQDetails,
    }
</script>

<svelte:head>
    <title>{pageTitle}</title>

    <meta
        name="description"
        content="{metaDescription}"
    />

    <meta
        name="keywords"
        content="{keywords}"
    />

    <meta
        property="og:site_name"
        content="{websiteName}"
    />

    {#if noIndex || active === false}
        <meta
            name="robots"
            content="noindex, nofollow"
        />
    {:else}
        <meta
            name="robots"
            content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"
        />
    {/if}
</svelte:head>

{#if product}
    <Product product="{product}" />
{/if}
<OpenGraph {...openGraphProps} />

<SchemaOrg {...schemaOrgProps} />
