<script lang="ts">
    import { getJson } from "$lib/data";
	import { Toast, ToastType } from "$lib/toast";
    import { addToast } from "$lib/store";

    import Skills from './skills.svelte';

    import Timeline from "./timeline.svelte";
</script>

<style>
    .main-card {
        background-color: var(--bg-secondary);
        border-radius: 1em;
        padding: .2em 2em 2em 2em;
        box-shadow: .5em .5em .5em var(--glow);
    }
    
    .flex-container {
        display: flex;
        align-items: center;
    }

    .profile {
        border-radius: 100%;
        height: 8em;
        width: 8em;
        padding: 1em 1em 1em 1em;
        border: .5em solid var(--bg-grad-3);
    }
    
    .about {
        padding: 0em 5% 0em 5%;
        font-size: 125%;
    }
    
    @media (max-width: 800px) {
        .flex-container {
            align-items: center;
            flex-direction: column;
            padding: 0px;
        }

        .about {
            font-size: 100%;
        }
    }

    .card-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 0em;
    }

    .card-header h1 {
        font-size: 2em;
    }

    .card-header h3 {
        font-size: 1.5em;
    }

    /* Skills Cards CSS */
    .container {
        padding-top: 3em;
        max-width: 90%;
        margin: auto;
    }

    .cards {
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        gap: 3em 3em;
        padding: 2em 0em 2em 0em;
        transition: all 0.2s;
    }

</style>

{#await getJson('/json/me.json')}
    <div class="card">
        <div class="card-header">
            <h1>Loading...</h1>
        </div>
    </div>
{:then info}
    <div class="main-card">
        <div class="card-header">
            <h1>{info.name}</h1>
            <h3 class="not-required">{info.job_title}</h3>
        </div>
        <hr />
        <div class="flex-container">
            <img class="profile not-required" src={info.profile_photo} alt="{info.name}'s Profile Photo">
            <p class="about">{@html info.about}</p>
        </div>
    </div>

    <div class="container">
        <h1>Skills</h1>
        <hr />
        <div class="cards">
            <Skills skills="{info.skills}"></Skills>
        </div>
    </div>

    <div class="container">
        <h1>Experience</h1>
        <hr />
        <!-- https://github.com/K-Sato1995/svelte-vertical-timeline -->
        <Timeline timelineData="{info.timeline}"></Timeline>
    </div>

    <div style="display: none;">{addToast(new Toast("Click on a skill to open a prompt", ToastType.Info, true, 4000))}</div>
    <div style="display: none;">{addToast(new Toast("Welcome!", ToastType.Success, true, 3000))}</div>
{:catch}
    <div class="card">
        <div class="card-header">
            <h1>Unable to load portfolio overview data</h1>
        </div>
    </div>
    <div style="display: none;">{addToast(new Toast("Unable to load me.json", ToastType.Error, true, 3000))}</div>
{/await}