<!-- 远程下拉选择器 -->
<template>
    <el-select class="app-remote-select" :empty-values="emptyValues" :placeholder="placeholder" remote filterable
        clearable>
        <template #header>
            <el-button text bg size="small" @click="$emit('reset')">{{ t('operation.reset') }}</el-button>
        </template>
        <el-option v-for="(item, index) in options" :key="index" :label="item[defaultProps.label]"
            :value="item[defaultProps.value]">
            <slot :option="item" :index="index"></slot>
        </el-option>
    </el-select>
</template>

<script lang="ts" setup>
import { i18n } from '@/stores';
import { computed, PropType } from 'vue'

const { global: { t } } = i18n

const props = defineProps({
    options: {
        type: Array as any, // eslint-disable-next-line
        required: true
    },
    optionProps: {
        type: Object as PropType<{ label?: string; value?: string; }>,
        default: () => ({})
    },
    emptyValues: {
        type: Array,
        default: () => ([null, undefined, 0])
    },
    placeholder: {
        type: String,
        default: i18n.global.t('common.pleasechoiceorenter')
    }
})

const defaultProps = computed(() => ({
    ...{ label: 'label', value: 'value' },
    ...props.optionProps
}))
</script>

<style lang="less">
@import './index.less';
</style>