import { __decorate } from "tslib";
import { ModelTool } from '@ibizstudio/runtime';
import { Component, Prop } from 'vue-property-decorator';
import { VueLifeCycleProcessing } from '../../../decorators';
import { EditorBase } from '../editor-base/editor-base';
/**
 * 文件上传编辑器
 *
 * @export
 * @class UploadEditor
 * @extends {EditorBase}
 */
let UploadEditor = class UploadEditor extends EditorBase {
    constructor() {
        super(...arguments);
        /**
         * 高拍仪图片
         *
         * @private
         * @type {Array<any>}
         */
        this.imgFiles = [];
    }
    /**
     * 编辑器初始化
     *
     * @memberof UploadEditor
     */
    async initEditor() {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j;
        await super.initEditor();
        const { editorType: type, editorStyle: style } = this.editorInstance;
        this.customProps.uploadparams = (_a = this.editorInstance.editorParams) === null || _a === void 0 ? void 0 : _a['uploadparams'];
        this.customProps.exportparams = (_b = this.editorInstance.editorParams) === null || _b === void 0 ? void 0 : _b['exportparams'];
        this.customProps.limit = ((_c = this.editorInstance.editorParams) === null || _c === void 0 ? void 0 : _c['limit']) ? JSON.parse(this.editorInstance.editorParams['limit']) : 9999;
        const editorTypeStyle = `${type}${style && style != 'DEFAULT' ? '_' + style : ''}`;
        switch (editorTypeStyle) {
            // 图片控件
            case 'PICTURE':
                this.customProps.multiple = true;
                this.customProps.accept = ((_d = this.editorInstance.editorParams) === null || _d === void 0 ? void 0 : _d['accept']) ? this.editorInstance.editorParams['accept'] : 'image/*';
                break;
            // 图片控件（单项）
            case 'PICTURE_ONE':
            case 'PICTURE_ONE_RAW':
            case 'FILEUPLOADER_ONE':
                this.customProps.multiple = false;
                this.customProps.accept = ((_e = this.editorInstance.editorParams) === null || _e === void 0 ? void 0 : _e['accept']) ? this.editorInstance.editorParams['accept'] : 'image/*';
                break;
            // 图片控件（旋转）
            case 'PICTURE_ROMATE':
                break;
            // 图片控件（磁盘图片）
            case 'PICTURE_DISKPIC':
                break;
            // 图片控件（信息展示）
            case 'PICTURE_INFO':
                break;
            // 文件上传
            case 'FILEUPLOADER':
                this.customProps.accept = ((_f = this.editorInstance.editorParams) === null || _f === void 0 ? void 0 : _f['accept']) ? this.editorInstance.editorParams['accept'] : '*';
                break;
            // 文件上传Base64
            case 'FILEUPLOADER_FILEUPLOADERBASE64':
                this.customProps.accept = ((_g = this.editorInstance.editorParams) === null || _g === void 0 ? void 0 : _g['accept']) ? this.editorInstance.editorParams['accept'] : '*';
                this.customProps.size = ((_h = this.editorInstance.editorParams) === null || _h === void 0 ? void 0 : _h['size']) ? this.editorInstance.editorParams['size'] : '*';
                break;
            // 文件上传（磁盘文件）
            case 'FILEUPLOADER_DISK':
                break;
            // 文件上传（可拖拽）
            case 'FILEUPLOADER_DRAG':
                this.customProps.isdrag = true;
                this.customProps.accept = ((_j = this.editorInstance.editorParams) === null || _j === void 0 ? void 0 : _j['accept']) ? this.editorInstance.editorParams['accept'] : '*';
                break;
            // 文件上传（可拖拽）
            case 'FILEUPLOADER_INFO':
                break;
            // 文件上传（高拍仪）
            case 'FILEUPLOADER_CAMERA':
                break;
            case 'FILEUPLOADER_USEWORKTEMP':
                break;
        }
    }
    /**
     * 绘制上传类组件
     *
     * @memberof UploadEditor
     */
    renderUploadEditor() {
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ name: this.editorInstance.name, value: this.value, disabled: this.disabled, context: this.context, viewparams: this.viewparams, data: JSON.stringify(this.contextData) }, this.customProps),
            on: { formitemvaluechange: this.editorChange },
            style: this.customStyle
        });
    }
    /**
     * 绘制上传类组件
     *
     * @memberof UploadEditor
     */
    renderUploadBase64() {
        return this.$createElement(this.editorComponentName, {
            domProps: {
                name: this.editorInstance.name,
                value: this.value,
                fileName: this.contextData.reportfile,
                disabled: this.disabled,
                accept: this.customProps.accept,
                size: this.customProps.size,
            },
            on: {
                "value-change": ($event) => {
                    this.editorChange({ name: this.editorInstance.name, value: $event.detail });
                },
                "file-name-change": ($event) => {
                    this.editorChange({ name: "reportfile", value: $event.detail });
                },
            },
            style: this.customStyle,
            class: "app-upload-base64"
        });
    }
    /**
     * 绘制磁盘上传组件
     *
     * @memberof UploadEditor
     */
    renderDiskUpload() {
        var _a, _b, _c, _d, _e, _f;
        let filekey = ((_c = (_b = ModelTool.getAppEntityKeyField((_a = this.containerCtrl) === null || _a === void 0 ? void 0 : _a.getPSAppDataEntity())) === null || _b === void 0 ? void 0 : _b.codeName) === null || _c === void 0 ? void 0 : _c.toLowerCase()) || '';
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ formItemName: this.editorInstance.name, value: this.value, disabled: this.disabled, context: this.context, viewparams: this.viewparams, data: JSON.stringify(this.contextData), folder: ((_f = (_e = (_d = this.containerCtrl) === null || _d === void 0 ? void 0 : _d.getPSAppDataEntity()) === null || _e === void 0 ? void 0 : _e.codeName) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || '', ownertype: this.editorInstance.name, ownerid: this.contextData[filekey], filekey: filekey }, this.customProps),
            on: { formitemvaluechange: this.editorChange },
            style: this.customStyle
        });
    }
    /**
     * 绘制高拍仪组件
     *
     * @memberof UploadEditor
     */
    renderCameraUpload() {
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ formItemName: this.editorInstance.name, value: this.value, disabled: this.disabled, data: JSON.stringify(this.contextData) }, this.customProps),
            on: { takePicture: (img) => { this.imgFiles.push(img); }
            },
            style: this.customStyle
        });
    }
    /**
     * 绘制内容
     *
     * @returns {*}
     * @memberof UploadEditor
     */
    render() {
        this.customProps.ignorefieldvaluechange = this.ignorefieldvaluechange;
        this.customProps.rowPreview = this.rowPreview;
        const { editorType: type, editorStyle: style } = this.editorInstance;
        const editorTypeStyle = `${type}${style && style != 'DEFAULT' ? '_' + style : ''}`;
        switch (editorTypeStyle) {
            case 'FILEUPLOADER':
            case 'PICTURE':
            case 'PICTURE_ROMATE':
            case 'FILEUPLOADER_DRAG':
            case 'PICTURE_INFO':
            case 'FILEUPLOADER_INFO':
            case 'FILEUPLOADER_ONE':
            case 'PICTURE_ONE':
            case 'PICTURE_ONE_RAW':
                return this.renderUploadEditor();
            case 'PICTURE_DISKPIC':
            case 'FILEUPLOADER_DISK':
                return this.renderDiskUpload();
            case 'FILEUPLOADER_CAMERA':
                return this.renderCameraUpload();
            case 'FILEUPLOADER_USEWORKTEMP':
                return this.renderDiskUpload();
            case 'FILEUPLOADER_FILEUPLOADERBASE64':
                return this.renderUploadBase64();
        }
    }
};
__decorate([
    Prop()
], UploadEditor.prototype, "ignorefieldvaluechange", void 0);
__decorate([
    Prop()
], UploadEditor.prototype, "rowPreview", void 0);
UploadEditor = __decorate([
    Component({}),
    VueLifeCycleProcessing()
], UploadEditor);
export default UploadEditor;
