<script lang="ts">
    import { navigate } from "svelte-routing"
    import { navigations, location, currentLang } from "../../store"

    $: languages = []

    $: {
        if ($navigations?.length) {
            $navigations.forEach((nav) => {
                if (!languages.includes(nav.locale)) {
                    languages.push(nav.locale)
                }
            })
            languages = languages
        }
    }

    const setLanguage = (lang: string) => {
        $currentLang = lang
        // $location.path = "/" + lang
        // navigate($location.path + $location.search, { replace: true })
    }
</script>

<div class="language-chooser">
    {#each languages as lang}
        <div class="lang" class:active="{$currentLang === lang}" on:click="{() => setLanguage(lang)}">
            {lang}
        </div>
    {/each}
</div>
