import { __decorate } from "tslib";
import { ModelTool } from '@ibizstudio/runtime';
import { Component, Prop } from 'vue-property-decorator';
import { PluginService } from '../../../app-service';
import { VueLifeCycleProcessing } from '../../../decorators';
import { EditorBase } from '../editor-base/editor-base';
/**
 * 自动完成编辑器
 *
 * @export
 * @class AutocompleteEditor
 * @extends {EditorBase}
 */
let AutocompleteEditor = class AutocompleteEditor extends EditorBase {
    constructor() {
        super(...arguments);
        /**
         * @description 插件工厂
         * @type {PluginService}
         * @memberof AutocompleteEditor
         */
        this.PluginFactory = PluginService.getInstance();
    }
    /**
     * 编辑器初始化
     *
     * @memberof AutocompleteEditor
     */
    async initEditor() {
        await super.initEditor();
        if (this.editorInstance.getPSAppDEACMode() &&
            this.editorInstance.getPSAppDEACMode().getPSDEACModeDataItems() &&
            this.editorInstance.getPSAppDEACMode().getPSDEACModeDataItems().length > 0) {
            this.customProps.dataItems = this.editorInstance.getPSAppDEACMode().getPSDEACModeDataItems();
        }
        this.customProps.acParams = ModelTool.getAcParams(this.editorInstance);
        this.customProps.deMajorField = ModelTool.getEditorMajorName(this.editorInstance);
        this.customProps.deKeyField = ModelTool.getEditorKeyName(this.editorInstance);
        this.acItemPlugin = ModelTool.getAcItemPlugin(this.editorInstance);
    }
    /**
     * 绘制内容
     *
     * @returns {*}
     * @memberof AutocompleteEditor
     */
    render() {
        var _a;
        if (!this.editorIsLoaded) {
            return null;
        }
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ name: this.editorInstance.name, value: this.value, disabled: this.disabled, data: this.contextData, service: this.service, context: this.context, editorType: this.editorInstance.editorType, viewparams: this.viewparams, acItemPlugin: this.acItemPlugin ? true : false, valueitem: ((_a = this.parentItem) === null || _a === void 0 ? void 0 : _a.valueItemName) || '' }, this.customProps),
            on: { formitemvaluechange: this.editorChange },
            style: this.customStyle,
            scopedSlots: {
                acItemPlugin: ({ item }) => {
                    if (this.acItemPlugin) {
                        const pluginInstance = this.PluginFactory.getPluginInstance('DEACMODE', this.acItemPlugin.pluginCode);
                        if (pluginInstance) {
                            return pluginInstance.renderAcItem(this.$createElement, item, this.value, this);
                        }
                    }
                }
            }
        });
    }
};
__decorate([
    Prop()
], AutocompleteEditor.prototype, "editorInstance", void 0);
AutocompleteEditor = __decorate([
    Component({}),
    VueLifeCycleProcessing()
], AutocompleteEditor);
export default AutocompleteEditor;
