<template>
    <div>
        <el-dropdown trigger="click" @command="handleSetSize">
            <div class="size-icon--style">
                <svg-icon class-name="size-icon" icon-class="size" style="font-size:12px;"/>
            </div>
            <template #dropdown>
                <el-dropdown-menu>
                    <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>
            </template>
        </el-dropdown>
    </div>
</template>

<script setup lang="ts">
import useAppStore from '@/store/modules/app';
import { computed, getCurrentInstance, ComponentInternalInstance, ref } from 'vue';
// import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n'

const { t } = useI18n()
const appStore = useAppStore();
const size = computed(() => appStore.size);
// const route = useRoute();
// const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const sizeOptions = ref([
    { label: t('message.layout.sizeLarge'), value: 'large' },
    { label: t('message.layout.sizeDefault'), value: 'default' },
    { label: t('message.layout.sizeSmall'), value: 'small' },
]);

function handleSetSize(size: any) {
    proxy!.$modal.loading(t('message.layout.setLoadingText'));
    appStore.setSize(size);
    setTimeout('window.location.reload()', 1000);
}
</script>

<style lang="scss" scoped>
.size-icon--style {
    font-size: 18px;
    line-height: 50px;
    padding-right: 7px;
}
</style>
