import { __decorate } from "tslib";
import { Component, Prop, Watch } from 'vue-property-decorator';
import { AppDefaultFormDetail } from '../app-default-form-detail/app-default-form-detail';
import { VueLifeCycleProcessing } from '../../../../decorators';
/**
 * 表单UI组件
 *
 * @export
 * @class AppDefaultFormItem
 * @extends {Vue}
 */
let AppDefaultFormItem = class AppDefaultFormItem extends AppDefaultFormDetail {
    constructor() {
        super(...arguments);
        /**
         * 属性标识
         *
         * @type {string}
         * @memberof AppDefaultFormItem
         */
        this.tipTag = '';
    }
    /**
     * 表单项值变化事件
     *
     * @memberof AppDefaultFormItem
     */
    onFormItemValueChange(...args) {
        this.$emit('formItemValueChange', ...args);
    }
    /**
     * 绘制基础复合编辑器
     *
     * @memberof AppDefaultFormItem
     */
    renderBaseCompositeEditor(refFormItem, name, editor, contentStyle) {
        var _a, _b, _c, _d, _e;
        if (Object.is(editor === null || editor === void 0 ? void 0 : editor.editorType, 'DATERANGE') || Object.is(editor === null || editor === void 0 ? void 0 : editor.editorType, 'DATERANGE_NOTIME')) {
            return (<app-date-range activeData={this.data} name={name} editorType={editor.editorType} refFormItem={refFormItem} disabled={(_a = this.runtimeModel) === null || _a === void 0 ? void 0 : _a.disabled} format={(_b = editor === null || editor === void 0 ? void 0 : editor.editorParams) === null || _b === void 0 ? void 0 : _b['TIMEFMT']} on-formitemvaluechange={(value) => {
                    this.onFormItemValueChange(value);
                }} style={contentStyle}></app-date-range>);
        }
        else if (Object.is(editor === null || editor === void 0 ? void 0 : editor.editorType, 'NUMBERRANGE')) {
            return (<app-number-range name={name} activeData={this.data} refFormItem={refFormItem} disabled={(_c = this.runtimeModel) === null || _c === void 0 ? void 0 : _c.disabled} on-formitemvaluechange={(value) => {
                    this.onFormItemValueChange(value);
                }} style={contentStyle ? contentStyle : 'width: 300px'}></app-number-range>);
        }
        else {
            return (<app-range-editor value={this.data[name]} activeData={this.data} name={name} editorType={editor === null || editor === void 0 ? void 0 : editor.editorType} refFormItem={refFormItem} disabled={(_d = this.runtimeModel) === null || _d === void 0 ? void 0 : _d.disabled} format={(_e = editor === null || editor === void 0 ? void 0 : editor.editorParams) === null || _e === void 0 ? void 0 : _e['TIMEFMT']} on-formitemvaluechange={(value) => {
                    this.onFormItemValueChange(value);
                }} style={contentStyle}></app-range-editor>);
        }
    }
    /**
     * 绘制复合表单项
     *
     * @returns
     * @memberof AppDefaultFormItem
     */
    renderCompositeItem() {
        var _a, _b;
        const { name, contentHeight, contentWidth } = this.detailsInstance;
        let editor = this.detailsInstance.getPSEditor();
        let formItems = this.detailsInstance.getPSDEFormItems();
        let editorType = editor === null || editor === void 0 ? void 0 : editor.editorType;
        // 设置高宽
        let contentStyle = '';
        contentStyle += contentWidth && contentWidth != 0 ? `width:${contentWidth}px;` : '';
        contentStyle += contentHeight && contentHeight != 0 ? `height:${contentHeight}px;` : '';
        contentStyle += ((_a = this.runtimeModel) === null || _a === void 0 ? void 0 : _a.visible) ? '' : 'display: none;';
        const refFormItem = [];
        if (formItems) {
            formItems === null || formItems === void 0 ? void 0 : formItems.forEach((formItem) => {
                refFormItem.push(formItem === null || formItem === void 0 ? void 0 : formItem.name);
            });
        }
        if ((editor === null || editor === void 0 ? void 0 : editor.editorType) !== 'USERCONTROL') {
            return this.renderBaseCompositeEditor(refFormItem, name, editor, contentStyle);
        }
        else {
            return (<app-default-editor editorInstance={editor} value={this.data[editor.name]} contextData={this.data} context={this.context} viewparams={this.viewparams} service={this.service} disabled={(_b = this.runtimeModel) === null || _b === void 0 ? void 0 : _b.disabled} ignorefieldvaluechange={this.ignorefieldvaluechange} on-change={(value) => {
                    this.onFormItemValueChange(value);
                }}/>);
        }
    }
    /**
     * 监听表单成员实例对象变化
     *
     * @type {*}
     * @memberof AppDefaultFormItem
     */
    detailsInstanceChange() {
        var _a, _b;
        super.detailsInstanceChange();
        const field = (_a = this.detailsInstance) === null || _a === void 0 ? void 0 : _a.getPSAppDEField();
        const entity = (_b = this.controlInstance) === null || _b === void 0 ? void 0 : _b.getPSAppDataEntity();
        this.tipTag = `${entity === null || entity === void 0 ? void 0 : entity.codeName.toUpperCase()}__${field === null || field === void 0 ? void 0 : field.codeName.toUpperCase()}`;
    }
    /**
     * 绘制内容
     *
     * @returns {*}
     * @memberof AppDefaultFormItem
     */
    render() {
        var _a, _b, _c, _d;
        const { detailClassNames } = this.renderOptions;
        let { name, caption, labelWidth, labelPos, showCaption, emptyCaption, detailStyle, compositeItem, contentWidth, contentHeight } = this.detailsInstance;
        let editor = this.detailsInstance.getPSEditor();
        let sysCss = this.detailsInstance.getLabelPSSysCss();
        let editorType = editor === null || editor === void 0 ? void 0 : editor.editorType;
        // 隐藏表单项
        if (editorType == 'HIDDEN') {
            return;
        }
        // 设置高宽
        let contentStyle = '';
        contentStyle += contentWidth && contentWidth != 0 ? `width:${contentWidth}px;` : '';
        contentStyle += contentHeight && contentHeight != 0 ? `height:${contentHeight}px;` : '';
        contentStyle += ((_a = this.runtimeModel) === null || _a === void 0 ? void 0 : _a.visible) ? '' : 'display: none;';
        let labelCaption = this.detailsInstance.captionItemName
            ? this.data[this.detailsInstance.captionItemName.toLowerCase()]
            : this.$tl((_b = this.detailsInstance.getCapPSLanguageRes()) === null || _b === void 0 ? void 0 : _b.lanResTag, caption);
        return (<app-form-item tipTag={this.tipTag} name={name} caption={labelCaption} isEmptyCaption={emptyCaption} isShowCaption={showCaption} labelWidth={labelWidth} labelPos={labelPos} detailsInstance={this.detailsInstance} uiStyle={detailStyle} itemRules={this.rules} required={(_c = this.runtimeModel) === null || _c === void 0 ? void 0 : _c.required} error={(_d = this.runtimeModel) === null || _d === void 0 ? void 0 : _d.error} class={detailClassNames} labelStyle={sysCss === null || sysCss === void 0 ? void 0 : sysCss.cssName} style={contentStyle} controlInstance={this.controlInstance}>
        {compositeItem ? this.renderCompositeItem() : this.$slots.default}
      </app-form-item>);
    }
};
__decorate([
    Prop()
], AppDefaultFormItem.prototype, "data", void 0);
__decorate([
    Prop()
], AppDefaultFormItem.prototype, "rules", void 0);
__decorate([
    Prop()
], AppDefaultFormItem.prototype, "context", void 0);
__decorate([
    Prop()
], AppDefaultFormItem.prototype, "viewparams", void 0);
__decorate([
    Prop()
], AppDefaultFormItem.prototype, "service", void 0);
__decorate([
    Prop()
], AppDefaultFormItem.prototype, "ignorefieldvaluechange", void 0);
__decorate([
    Watch('detailsInstance', { immediate: true })
], AppDefaultFormItem.prototype, "detailsInstanceChange", null);
AppDefaultFormItem = __decorate([
    Component({}),
    VueLifeCycleProcessing()
], AppDefaultFormItem);
export { AppDefaultFormItem };
