<script lang="ts">
    let {
        title,
        date = "", // date posted
        dateUpdated = "",
        subtitle = "",
        banner = "",
        bannerAlt = "",
        tags = [],
        pixelated,
    }: {
        title: string;
        date?: string;
        dateUpdated?: string;
        subtitle?: string;
        banner?: string;
        bannerAlt?: string;
        tags?: string[];
        pixelated?: boolean;
    } = $props();

</script>

{#snippet titles({title, subtitle, date}: {title: string, subtitle: string, date: string})}
        <h1 class="title">{title}</h1>
	<div class="title-container">
        <div class="title-text-container">
            {#if subtitle}
                <p class="subtitle">[ {subtitle} ]</p>
            {/if}
            {#if tags.length}
                <div class="tag-container">
                    {#each tags as tag}
                        <span class="post-tag">{tag}</span>
                    {/each}
                </div>
            {/if}
        </div>
        {#if date}
            <div class="date-container">
                <p class="date">posted :: {date}</p>
                {#if dateUpdated}
                    <p class="date">last updated :: {dateUpdated}</p>
                {/if}
            </div>
        {/if}
    </div>
{/snippet}

<div class="container">
    {#if banner && banner !== ""}
        {#if pixelated}
            <img class="banner pixelated-img" src="{banner}" alt="{bannerAlt}">
        {:else}
            <img class="banner" src="{banner}" alt="{bannerAlt}">
        {/if}
    {/if}
    {@render titles({title, subtitle, date})}
    <hr>
</div>

<style>
    .container {
        width: 100%;
    }

	.banner {
		max-height: 300px;
        width: 100%;
        object-fit: cover;
	}

    .title-container {
        display: flex;
        flex-direction: row;
        /* align-items: flex-end; */
        gap: 16px;
        margin: 8px 0;
    }

    .title-text-container {
        width: fit-content;
        display: flex;
        flex-direction: column;
        flex: 1;
        gap: 8px;
    }

    .tag-container {
        display: flex;
        gap: 4px;
        flex-direction: row;
        flex-wrap: wrap;
        margin-bottom: 4px;
    }

    .date-container {
        width: fit-content;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
    }

    .title {
        box-sizing: border-box;
        height: fit-content;
        margin: 0;
        margin-top: var(--margin-header-top);
    }

    .date {
        font-weight: 500;
        font-family: var(--font-mono);
        font-size: 1.0rem;
        line-height: 1.4rem;
        font-style: italic;
        margin: 0;
        color: var(--color-highlight);
    }

    .subtitle {
        font-family: var(--font-mono);
        font-weight: 500;
        font-size: 1.0rem;
        line-height: 1.4rem;
        margin: 0;
    }

    @media screen and (max-width: 800px) {
        .title-container {
            flex-direction: column;
            align-items: flex-start;
            gap: 4px;
        }

        .date-container {
            align-items: flex-start;
        }

        .date {
            font-size: 0.9rem;
            line-height: 1.2rem;
        }
    }
</style>