<template>
    <div class="el-dict-select">
        <component :is="name" :options="currentOptions" :labelKey="labelKey" :valueKey="valueKey" v-bind="$attrs" v-on="$listeners"></component>
    </div>
</template>

<script>
import Select from '../../select'
import Option from '../../option'
import dictSelect from "./dictSelect";
import dictRadio from "./dictRadio";
import dictCheckbox from "./dictCheckbox";
export default {
    name: 'ElDictSelect',
    components: {
        Select,
        Option,
        dictSelect,
        dictRadio,
        dictCheckbox,
    },
    props: {
        options: {
            type: Array,
            default: () => []
        },
        type: {
            type: String,
            default: ''
        },
        filter: Function,
        labelKey: {
            type: String,
            default() {
                return this.$ELEMENT.dictSelect?.labelKey || 'dictLabel'
            }
        },
        valueKey: {
            type: String,
            default() {
                return this.$ELEMENT.dictSelect?.valueKey || 'dictValue'
            }
        },
        isRadio: {
            type: Boolean,
            default: false
        },
        isChecked: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        name() {
            if (this.isRadio) {
                return 'dictRadio'
            }
            if (this.isChecked) {
                return 'dictCheckbox'
            }
            return 'dictSelect'
        },
        currentOptions() {

            if (this.type) {
                return this.getOptions(this.type)
            }
            return this.options
        }
    },
    methods: {
        getOptions(type) {
            if (this.$ELEMENT.dictSelect.getOptions) {
                if (this.filter) {
                    return this.$ELEMENT.dictSelect.getOptions(type)
                }
                return this.$ELEMENT.dictSelect.getOptions(type)
            }
            console.log(new Error('请实现数据字典getOptions方法'))
            return []
        }
    },
}
</script>

<style scoped>

</style>
