<template>
  <el-dropdown trigger="click" @command="handleSetSize">
    <div>
      <svg-icon class-name="size-icon" icon-class="size" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of sizeOptions" :key="item.value" :disabled="size===item.value" :command="item.value">
        {{ item.label }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  computed: {
    sizeOptions() {
      return [
        { label: this.$t('size.default'), value: 'default' },
        { label: this.$t('size.medium'), value: 'medium' },
        { label: this.$t('size.small'), value: 'small' },
        { label: this.$t('size.mini'), value: 'mini' }
      ]
    },
    size() {
      return this.$store.getters.size
    }
  },
  methods: {
    handleSetSize(size) {
      this.$ELEMENT.size = size
      this.$store.dispatch('app/setSize', size)
      this.refreshView()
      this.$message({
        message: this.$t('size.switchSuccess'),
        type: 'success'
      })
    },
    refreshView() {
      this.$router.go(0)
    }
  }
}
</script>
