<script>
    import Header from '$lib/navigation/header.svelte';
    import Nav from '$lib/navigation/nav.svelte';
    import { uuid } from '$lib/stores/uuid.js';
    import { onMount } from 'svelte';
    const title = "Your Data";

    let data = [
        {
            "domain": "User not Found",
            "atime": "User not Found"
        }
    ]

    async function fetchData() {
        if ($uuid != "null") {
            const url = `https://owlboard.info/api/v2/user/${$uuid}`
            const res = await fetch(url);
            const json = await res.json();
            if (json.length) {
                data = json
            }
        }
    }

    onMount(async () => {
        fetchData();
    })
</script>
 
<Header {title} />

<p>OwlBoard stored as little data about you as possible to offer the service.</p>
<p>Besides your randomly generated UUID which is used to authorise your staff access we store the following data:</p>
<br><br>

{#if data[0].domain != "User not Found"}
  <p class="api_response">Registration Domain: {data[0]['domain']}</p>
  <p class="api_response">Access Time: {data[0]['atime']}</p>
{:else}
  <p class="api_response">You are not registered, we don't have any data stored.</p>
{/if}
 
<Nav />

<style>
    .api_response {
        color: white;
    }
</style>