import { __decorate } from "tslib";
import { ModelTool, Util } from '@ibizstudio/runtime';
import { Component, Prop } from 'vue-property-decorator';
import { VueLifeCycleProcessing } from '../../../decorators';
import { EditorBase } from '../editor-base/editor-base';
/**
 * 下拉列表编辑器
 *
 * @export
 * @class DropdownListEditor
 * @extends {EditorBase}
 */
let DropdownListEditor = class DropdownListEditor extends EditorBase {
    /**
     * 编辑器初始化
     *
     * @memberof DropdownListEditor
     */
    async initEditor() {
        var _a, _b, _c, _d;
        await super.initEditor();
        const { placeHolder } = this.editorInstance;
        let appDEField = (_b = (_a = this.parentItem) === null || _a === void 0 ? void 0 : _a.getPSAppDEField) === null || _b === void 0 ? void 0 : _b.call(_a);
        this.customProps.valueType = ModelTool.isNumberField(appDEField) ? 'number' : 'string';
        this.customProps.placeholder = placeHolder || this.$t('components.dropdownlist.placeholder');
        switch ((_c = this.editorInstance) === null || _c === void 0 ? void 0 : _c.editorType) {
            // 下拉列表框
            case 'DROPDOWNLIST':
                break;
            // 下拉列表框(100宽度)
            case 'DROPDOWNLIST_100':
                this.customStyle.width = '100px';
                break;
            // 下拉列表框(多选)
            case 'MDROPDOWNLIST':
                this.customProps.isMultiple = true;
                break;
            // 下拉列表框(corn表达式)
            case 'MDROPDOWNLIST_CRONEDITOR':
                break;
            // 下拉列表框(隐藏选项)
            case 'DROPDOWNLIST_HIDDEN':
                break;
            // 下拉列表框(多选穿梭框)
            case 'MDROPDOWNLIST_TRANSFER':
                break;
        }
        let codeList = (_d = this.editorInstance) === null || _d === void 0 ? void 0 : _d.getPSAppCodeList();
        if (codeList && (codeList === null || codeList === void 0 ? void 0 : codeList.isFill)) {
            Object.assign(this.customProps, {
                valueSeparator: codeList.valueSeparator,
                tag: codeList.codeName,
                codeList: codeList,
                codelistType: codeList.codeListType
            });
        }
    }
    /**
     * 编辑器change事件
     *
     * @param {*} value
     * @memberof DropdownListEditor
     */
    handleChange($event) {
        this.editorChange({ name: this.editorInstance.name, value: $event });
    }
    /**
     * 绘制下拉列表组件
     *
     * @memberof DropdownListEditor
     */
    renderDropdownList() {
        return this.$createElement(this.editorComponentName, {
            key: this.cacheUUID,
            props: Object.assign({ name: this.editorInstance.name, itemValue: this.value, disabled: this.disabled, data: this.contextData, context: this.context, viewparams: this.viewparams, ignorefieldvaluechange: this.ignorefieldvaluechange }, this.customProps),
            on: { change: this.handleChange },
            style: this.customStyle,
        });
    }
    /**
     * 绘制下拉列表(cron表达式)组件
     *
     * @memberof DropdownListEditor
     */
    renderDropdownCron() {
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ disabled: this.disabled }, this.customProps),
        });
    }
    /**
     * 绘制下拉列表(多选穿梭框)组件
     *
     * @memberof DropdownListEditor
     */
    DropdownTransfer() {
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ disabled: this.disabled }, this.customProps),
        });
    }
    /**
     * 绘制内容
     *
     * @returns {*}
     * @memberof DropdownListEditor
     */
    render() {
        if (!this.editorIsLoaded) {
            return null;
        }
        if (!this.cacheUUID) {
            this.cacheUUID = Util.createUUID();
        }
        const { editorType: type, editorStyle: style } = this.editorInstance;
        const editorTypeStyle = `${type}${style && style != 'DEFAULT' ? '_' + style : ''}`;
        switch (editorTypeStyle) {
            case 'DROPDOWNLIST':
            case 'DROPDOWNLIST_100':
            case 'DROPDOWNLIST_HIDDEN':
            case 'MDROPDOWNLIST_TRANSFER':
            case 'MDROPDOWNLIST':
            case 'DROPDOWNLIST_TreeCodeList':
            case 'MDROPDOWNLIST_TreeCodeList':
                return this.renderDropdownList();
            case 'MDROPDOWNLIST_CRONEDITOR':
                return this.renderDropdownCron();
        }
    }
};
__decorate([
    Prop()
], DropdownListEditor.prototype, "ignorefieldvaluechange", void 0);
__decorate([
    Prop()
], DropdownListEditor.prototype, "editorInstance", void 0);
DropdownListEditor = __decorate([
    Component({}),
    VueLifeCycleProcessing()
], DropdownListEditor);
export default DropdownListEditor;
