import { __decorate } from "tslib";
import { DataTypes, ModelTool } from '@ibizstudio/runtime';
import { Component } from 'vue-property-decorator';
import { VueLifeCycleProcessing } from '../../../decorators';
import { EditorBase } from '../editor-base/editor-base';
/**
 * 文本框编辑器
 *
 * @export
 * @class SpanEditor
 * @extends {EditorBase}
 */
let SpanEditor = class SpanEditor extends EditorBase {
    /**
     * 编辑器初始化
     *
     * @memberof SpanEditor
     */
    async initEditor() {
        await super.initEditor();
        const { editorType: type, editorStyle: style } = this.editorInstance;
        const editorTypeStyle = type + (style && style != 'DEFAULT' ? '_' + style : '');
        switch (editorTypeStyle) {
            case 'SPAN':
                await this.initSpan();
                break;
            case 'SPANEX':
                this.initSpanEX();
                break;
            case 'SPAN_HTML':
                this.initSpanHtml();
                break;
            case 'SPAN_COLORSPAN':
                await this.initSpanColorSpan();
                break;
            case 'SPAN_AFTERTIME':
                this.initSpanAfterTime();
                break;
            case 'SPAN_ADDRESSPICKUP':
                await this.initAddressPickUp();
                break;
        }
    }
    /**
     * 解析标签值格式化参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    initFormatParams() {
        var _a, _b, _c;
        let unitName = (_a = this.parentItem) === null || _a === void 0 ? void 0 : _a.unitName;
        let appDeField = (_c = (_b = this.parentItem) === null || _b === void 0 ? void 0 : _b.getPSAppDEField) === null || _c === void 0 ? void 0 : _c.call(_b);
        if (appDeField === null || appDeField === void 0 ? void 0 : appDeField.stdDataType) {
            this.customProps.dataType = DataTypes.toString(appDeField.stdDataType);
        }
        if (appDeField === null || appDeField === void 0 ? void 0 : appDeField.valueFormat) {
            this.customProps.valueFormat = appDeField === null || appDeField === void 0 ? void 0 : appDeField.valueFormat;
        }
        if (unitName) {
            this.customProps.unitName = unitName;
        }
    }
    /**
     * 解析标签数值精度参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    initNumberParams() {
        var _a, _b;
        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.precision = ModelTool.getPrecision(this.editorInstance, appDeField);
    }
    /**
     * 解析标签代码表参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    async initCodelistParams() {
        var _a, _b;
        let codeList = (_b = (_a = this.editorInstance) === null || _a === void 0 ? void 0 : _a.getPSAppCodeList) === null || _b === void 0 ? void 0 : _b.call(_a);
        if (codeList) {
            this.customProps.tag = codeList === null || codeList === void 0 ? void 0 : codeList.codeName;
            this.customProps.codelistType = codeList === null || codeList === void 0 ? void 0 : codeList.codeListType;
            this.customProps.renderMode = codeList === null || codeList === void 0 ? void 0 : codeList.orMode;
            this.customProps.valueSeparator = codeList === null || codeList === void 0 ? void 0 : codeList.valueSeparator;
            this.customProps.textSeparator = codeList === null || codeList === void 0 ? void 0 : codeList.textSeparator;
        }
    }
    /**
     * 解析标签参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    async initSpan() {
        var _a, _b;
        let codeList = (_b = (_a = this.editorInstance) === null || _a === void 0 ? void 0 : _a.getPSAppCodeList) === null || _b === void 0 ? void 0 : _b.call(_a);
        this.customProps.codeList = codeList;
        this.customProps.data = JSON.stringify(this.contextData);
        this.customProps.context = this.context;
        this.customProps.viewparams = this.viewparams;
        this.initFormatParams();
        this.initNumberParams();
    }
    /**
     * 解析旧标签参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    initSpanEX() {
        var _a;
        this.customProps.data = JSON.stringify(this.contextData);
        this.customProps.readonly = true;
        this.customProps.disabled = true;
        this.customProps.placeholder = (_a = this.editorInstance) === null || _a === void 0 ? void 0 : _a.placeHolder;
    }
    /**
     * 解析标签（格式化信息）参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    initSpanHtml() {
        this.customProps.data = JSON.stringify(this.contextData);
    }
    /**
     * 解析标签（颜色）参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    async initSpanColorSpan() {
        this.customProps.data = this.contextData;
        await this.initCodelistParams();
        this.customProps.context = this.context;
        this.customProps.viewparams = this.viewparams;
    }
    /**
     * 解析标签（多久之前）参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    initSpanAfterTime() {
        this.customProps.data = JSON.stringify(this.contextData);
        this.customProps.context = this.context;
        this.customProps.viewparams = this.viewparams;
    }
    /**
     * 解析标签（地址栏）参数
     *
     * @return {*}
     * @memberof SpanEditor
     */
    async initAddressPickUp() {
        var _a, _b;
        let codeList = (_b = (_a = this.editorInstance) === null || _a === void 0 ? void 0 : _a.getPSAppCodeList) === null || _b === void 0 ? void 0 : _b.call(_a);
        this.customProps.codeList = codeList;
        this.customProps.data = JSON.stringify(this.contextData);
        this.customProps.editorType = 'ADDRESSPICKUP';
        this.customProps.context = this.context;
        this.customProps.viewparams = this.viewparams;
        this.initFormatParams();
        this.initNumberParams();
        await this.initCodelistParams();
    }
    /**
     * 绘制标签（格式化信息）
     *
     * @memberof SpanEditor
     */
    renderSpanHtml() {
        const tempNode = this.$createElement('div', {
            domProps: {
                innerHTML: this.value,
            },
            class: 'span-html',
        });
        return tempNode;
    }
    /**
     * 绘制内容
     *
     * @returns {*}
     * @memberof SpanEditor
     */
    render(h) {
        if (!this.editorIsLoaded) {
            return;
        }
        const { editorType: type, editorStyle: style } = this.editorInstance;
        const editorTypeStyle = type + (style && style != 'DEFAULT' ? '_' + style : '');
        if (editorTypeStyle == 'SPAN_HTML') {
            return this.renderSpanHtml();
        }
        return (<div class='span-wrapper'>
                {h(this.editorComponentName, {
                props: Object.assign({ name: this.editorInstance.name, value: this.value, disabled: this.disabled, data: this.contextData }, this.customProps),
                style: this.customStyle,
                on: { change: this.editorChange },
            })}
            </div>);
    }
};
SpanEditor = __decorate([
    Component({}),
    VueLifeCycleProcessing()
], SpanEditor);
export default SpanEditor;
