<script setup>
const route = useRoute()
const championAlias = route.params.alias

const { data : championData } = await useFetch("/api/champion/" + championAlias.toLowerCase())
const championId = championData.value.id

const state = ref("runes")
</script>

<template>
    <Head>
        <Title>{{ championData.name }} - BuildPath</Title>
    </Head>

    <SideBar :champion-name="championData.name" @state-change="(newState) => state = newState"/>

    <!-- <div style="display: flex; width: fit-content; margin: auto; margin-left: 330px;"> -->
    <div style="margin-top: 64px; margin-left: 339px;">
        <ChampionTitle :champion-id="championId" :winrate="championData.winrate" :pickrate="championData.pickrate" :game-count="championData.gameCount" />
        <RuneSelector v-if="state == 'runes' && championData.gameCount > 0" style="margin: auto; margin-top: 40px;" :runes="championData.runes" />
        <ItemViewer v-if="state == 'items' && championData.gameCount > 0" style="margin:auto; margin-top: 40px;" :builds="championData.builds" />
        <h2 v-if="championData.gameCount == 0" style="margin: auto; margin-top: 20px; width: fit-content;">Sorry, there is no data for this champion :(</h2>
    </div>
    <!-- <ItemViewer v-if="championData.gameCount > 0" style="margin-top: 64px; margin-left: 64px;" :builds="championData.builds" /> -->
    <!-- </div> -->
</template>

<style>
</style>