<script lang="ts">
    import Header from "$lib/navigation/header.svelte";
    import Nav from "$lib/navigation/nav-ldb.svelte";
    import PublicLdb from "$lib/ldb/public-ldb.svelte";
    import StaffLdb from "$lib/ldb/staff/staff-ldb.svelte";
    import { uuid } from "$lib/stores/uuid.js";
    import { onMount } from "svelte";

    let title = "Loading";

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

    let station: string;
    let staff: boolean;
    let uuidValue: string;
    let blockLoading: boolean = true;

    $: uuidValue = $uuid;

    onMount(async () => {
        station = (await getHeadcode()) || "";
        if (uuidValue !== null && uuidValue !== "" && uuidValue !== "null") {
            staff = true;
            title = "Staff Board";
        } else {
            title = "Public Board";
        }

        blockLoading = false;
    });
</script>

<svelte:head>
    <meta name="robots" content="noindex">
</svelte:head>

<Header {title} />

{#if !blockLoading}
    {#if !staff}
        <PublicLdb {station} bind:title />
    {:else}
        <StaffLdb {station} bind:title />
    {/if}
{/if}

<Nav />
