<script>
    import Header from '$lib/navigation/header.svelte'
    import Nav from '$lib/navigation/nav.svelte'
    
    import { onMount } from 'svelte'

    const title = "Timetable Results"

    async function getHeadcode() {
        return new URLSearchParams(window.location.search).get('headcode');
    }

    onMount(async () => {
        const headcode = await getHeadcode();
        document.getElementById('headcode').textContent = headcode;
        const data = await fetch(`https://owlboard.info/api/v1/train/headcode/today/${headcode}`)
        document.getElementById('data_raw').textContent = await data.text();
    })

 </script>
 
 <svelte:head>
    <title>OwlBoard {title}</title>
 </svelte:head>

 <Header {title} />
 
 <p>Headcode: <span id="headcode"></span></p>

 <p id="data_raw"></p>
 
 <Nav />