<template>
  <v-select
    v-model="locale"
    :items="items"
    :key="`locale-${locale}`"
    density="compact"
    variant="plain"
    :hide-details="true"
  >
    <template v-slot:selection="data">
      <v-img :src="data.item.raw.logo" left :width="16" class="mr-2"/>
      <span>{{ data.item.title }}</span>
    </template>

    <template v-slot:item="{ props, item }">
      <v-list-item v-bind="props">
        <template v-slot:prepend>
          <v-img :src="item.raw.logo" :width="16" class="mr-2"/>
        </template>
      </v-list-item>
    </template>
  </v-select>
</template>

<script setup lang="ts">
  const items = [
    { value: 'fr', title: 'FR', logo: '/images/logos/french_flag.svg' },
    { value: 'en', title: 'EN', logo: '/images/logos/us-uk_flag.svg' },
  ]

  const { setLocale } = useI18n()

  const locale = ref('fr')

  watch(locale, () => {
    setLocale(locale.value)
  });
</script>

<style scoped lang="scss">
:deep(.v-field__input) {
  padding: 0;
}

:deep(.v-select__menu-icon) {
  font-size: 15px;
  margin-top: 1px;
}

:deep(.v-list) {
  width: 72px;
}

:deep(.v-list-item) {
  padding: 24px;
}

:deep(.v-list-item__content) {
  display: flex;
  flex-direction: row;

  .v-avatar {
    width: 18px;
    height: 18px;
  }
}
</style>