<script lang="ts">
    import BannerTitle from "$lib/banner-title.svelte";
    import Header from "$lib/header.svelte";
    import Footer from "$lib/footer.svelte";
    import TableOfContents from "$lib/table-of-contents.svelte";
    import type { Project } from './projects';
    import { projects } from './projects';
    import { browser } from '$app/environment';

    let getActiveProjects = function(projects: Project[], isActive: boolean): Project[] {
        var result: Project[] = [];
        projects.forEach(project => {
            if (project.isActive == isActive) {
                result.push(project);
            }
        });
        return result;
    }
</script>

<Header />

<BannerTitle title="My Disordered Projects" banner="projects/banner.webp" />

<p>This is a listing of some of my more noteworthy projects that can be found on the web.</p>

{#if browser}
    <TableOfContents {document}/>
{/if}

<h2>Active Projects</h2>
{#each getActiveProjects(projects, true) as activeProject}
    {@render projectSummary({ project: activeProject })}
{/each}

<h2>Past Projects</h2>
{#each getActiveProjects(projects, false) as pastProject}
    {@render projectSummary({ project: pastProject })}
{/each}

<Footer />

{#snippet projectSummary({
    project
}: {
    project: Project;
})}
    <div>
        <h3 id="{project.id}">{project.title}</h3>
        {#if project.subtitle}
        <p class="subtitle">» {project.subtitle}</p>
        {/if}
        {#if project.banner}
        <img class="banner" src="{project.banner}">
        {/if}
        {#if project.icon}
        <img class="icon" src="{project.icon}">
        {/if}
        {#each project.paragraphs as paragraph}
            <p>{@html paragraph}</p>
        {/each}
        <ul>
            {#each project.links as link}
                <li><a href="{link.link}">{@html link.text}</a></li>
            {/each}
        </ul>
    </div>
{/snippet}

<style>
    .subtitle {
        color: var(--color-highlight);
        font-weight: 700;
        font-style: italic;
        margin-top: 0;
    }
    
    .banner {
        width: 80%;
        margin-left: auto;
        margin-right: auto;
        display: flex;
    }

    .icon {
        float: left;
        margin: 16px 16px 16px 0;
        width: 20%;
    }
</style>