<template>
    <div class="page page-shadow">
        <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">
                <icon
                    name="icon_ok"
                    :size="24"
                    color="#4CAF50"
                />
            </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);
    color: var(--white);
    font-weight: bold;
    margin-bottom: 24px;
}
.lang-item {
    background: var(--main-bg);
    border-radius: 14px;
    padding: 18px 18px;
    font-size: var(--font-size-20);
    margin-bottom: 24px;
    color: var(--white);
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}
.lang-item.active {
    border-radius: 10px;
    background: rgba(255, 209, 216, 0.85);
}
.check {
    margin-left: auto;
    color: var(--main-bg);
    font-size: var(--font-size-16);
}
</style>
