<template>
  <view class="language-switcher" @click="handleSwitch">
    <text class="language-icon">🌐</text>
    <text class="language-text">{{ currentLocaleName }}</text>
  </view>
</template>

<script setup>
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useLocaleStore } from '@/store/locale'

const { t } = useI18n()
const localeStore = useLocaleStore()

const currentLocaleName = computed(() => localeStore.getCurrentLocaleName())

const handleSwitch = () => {
  const success = localeStore.toggleLocale()
  if (success) {
    uni.showToast({
      title: t('components.languageSwitcher.switchSuccess'),
      icon: 'success',
      duration: 1500
    })
  } else {
    uni.showToast({
      title: t('components.languageSwitcher.switchFailed'),
      icon: 'error',
      duration: 1500
    })
  }
}
</script>

<style lang="scss" scoped>
.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8rpx;
  background: rgba(255, 255, 255, 0.2);
  padding: 12rpx 24rpx;
  border-radius: 30rpx;
  backdrop-filter: blur(10rpx);
  border: 1rpx solid rgba(255, 255, 255, 0.3);
  
  .language-icon {
    font-size: 28rpx;
  }
  
  .language-text {
    font-size: 24rpx;
    color: #ffffff;
    font-weight: 500;
  }
}
</style>
