<script setup lang="ts">
const props = defineProps<{
  championId: number,
  winrate: number,
  pickrate: number,
  gameCount: number
}>()

const winrate = ref((props.winrate * 100).toFixed(2))
watch(() => props.winrate, () => {winrate.value = (props.winrate * 100).toFixed(2)})
const pickrate = ref((props.pickrate * 100).toFixed(2))
watch(() => props.pickrate, () => {pickrate.value = (props.pickrate * 100).toFixed(2)})

const { data: championData } : ChampionResponse = await useFetch(CDRAGON_BASE + "plugins/rcp-be-lol-game-data/global/default/v1/champions/" + props.championId + ".json")
const championName = championData.value.name
const championDescription = championData.value.title
</script>

<template>
    <div style="display: flex; width: fit-content;">
        
        <div class="champion-title-img-container">
        <NuxtImg width="160" height="160" class="champion-title-img" :src="CDRAGON_BASE + 'plugins/rcp-be-lol-game-data/global/default/v1/champion-icons/' + championId + '.png'"/>
        </div>

        <div id="ct-info-container">
            <h1>{{ championName }}</h1>
            <h3 id="ct-desc">{{ championDescription }}</h3>

            <div id="ct-basic-stat-container">
                <h2 class="ct-basic-stat">{{ winrate }}% win.</h2>
                <h2 class="ct-basic-stat ct-basic-stat-margin">{{ pickrate }}% pick.</h2>
                <h2 class="ct-basic-stat">{{ gameCount }} games</h2>
            </div>
        </div>
    </div>
</template>

<style>
.champion-title-img-container {
    width: 160px;
    height: 160px;
    overflow: hidden;

    border: 1px solid var(--color-on-surface);
}
.champion-title-img {
    width: 160px;
    height: 160px;
    transform: translate(4px, 4px) scale(1.2, 1.2);

    user-select: none;
}
#ct-info-container {
    margin-left: 15px; 
    margin-top: 5px;
}
.ct-basic-stat-margin {
    margin-left: 20px; 
    margin-right: 20px;
}
#ct-desc {
    margin-top: 5px;
}
#ct-basic-stat-container {
    margin-top: 30px; 
    display: flex;
}

@media only screen and (max-width: 650px) {
    .champion-title-img-container {
        width: 86px;
        height: 86px;
    }
    .champion-title-img {
        width: 86px;
        height: 86px;
    }
    #ct-desc {
        display: none;
    }
    .ct-basic-stat {
        text-align: center;
    }
    .ct-basic-stat-margin {
        margin-left: 2px; 
        margin-right: 2px;
    }
    #ct-basic-stat-container {
        margin-top: 10px;
    }
    #ct-info-container {
        margin-left: 10px;
        margin-top: 0px;
        max-width: 220px;
    }
}
</style>