<script>
    export let id;
    import { settings } from "./store.js";
    const fetchNode = (async () => {
        $settings = JSON.parse(localStorage["settings"])
        console.log("settings", $settings)
        const response = await fetch(`http://127.0.0.1:5000/node/${id}/uprank/${$settings.ranking}.json`);
        return await response.json();
    })();
    const converter = new showdown.Converter();

    import { replaceWiki } from "./util.js";
</script>

<main>
    This is nodes module
    {#await fetchNode}
        .. Waiting
    {:then result}
        <div>
            New Node <span class="node-title">{result.node.uri}</span>
            {#each result.node.subnodes as subnode}
                <div>
                    <h3>Subnode user: {subnode.user}</h3>
                    {#if typeof subnode.content === "string"}
                        {@html converter.makeHtml(replaceWiki(subnode.content))}
                    {/if}
                </div>
            {/each}
        </div>
        <div>
            <h1>Backlinks</h1>
            {#each result.back_links as back_link}
                <div><a href='/node/{back_link}'>{back_link}</a></div>
            {/each}
        </div>
    {/await}
</main>

<style>
    div {
        margin-bottom: 10px;
    }
    .node-title {
        font-weight: bold;
    }
</style>
