<template>
    <div class="page">
        <div class="title">{{ t('language.selectLang') }}</div>
        <div v-for="item in localesList" :key="item" class="lang-item" :class="{ active: currentLang === item }" @click="changeLang(item)">
            {{ t(`language.${item}`) }}
            <span v-if="currentLang === item" class="check">✔</span>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { ref } from 'vue'
import { localesList } from '@/i18n'
import { lang } from '@/composables/config'
const { locale, t } = useI18n()
const currentLang = ref(lang.value || locale.value)
function changeLang(langValue: string) {
    locale.value = langValue
    lang.value = langValue
    currentLang.value = langValue
}
</script>

<style scoped lang="scss">
.title {
    font-size: var(--font-size-22);
    font-weight: bold;
    margin-bottom: 24px;
}
.lang-item {
    background: var(--main-bg);
    border-radius: 14px;
    padding: 18px 18px;
    font-size: var(--font-size-18);
    margin-bottom: 16px;
    color: var(--main-yellow);
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}
.lang-item.active {
    background: var(--main-yellow);
    color: var(--main-bg);
    font-weight: bold;
}
.check {
    margin-left: auto;
    color: var(--main-bg);
    font-size: var(--font-size-18);
}
</style>
