import { jsx as _jsx } from "react/jsx-runtime";
import { ClickAwayListener } from "@material-ui/core";
import { BaseDataControl } from "./BaseDataControl";
import { ObserveState } from "../../CommonUI/StateManagement/ObserveState";
import { StateManager } from "../../CommonUI/StateManagement/StateManager";
import { Layer } from "../../CommonUI/Components/Layer";
import { FileUploadLayer } from "../../CommonUI/BuildUI/FileUploadLayer";
export class BaseFileControl extends BaseDataControl {
    constructor() {
        super(...arguments);
        this.showFileName = true;
        this.showFileSize = true;
        this.showPreview = true;
        this.filesLimit = 3;
        this.showLayer = false;
        this.openLayer = (event) => {
            event.stopPropagation();
            this.showLayer = true;
            StateManager.propertyChanged(this, "showLayer");
        };
        this.onClose = () => {
            this.showLayer = false;
            StateManager.propertyChanged(this, "showLayer");
        };
        this.addFiles = (files) => {
            if (this.valueName) {
                let oldfiles = this.getFileObjects();
                this.setFormDataValue(this.valueName, [...files, ...oldfiles]);
            }
        };
        this.deleteFile = (_file, index) => {
            if (this.valueName) {
                let oldfiles = this.getFileObjects();
                oldfiles.splice(index, 1);
                this.setFormDataValue(this.valueName, oldfiles);
            }
        };
        this.getFileObjects = () => {
            return this.valueName ? this.getFormDataValue(this.valueName) || [] : [];
        };
    }
    renderLayerContent() {
        const files = this.getFileObjects();
        return (_jsx(ObserveState, { listenTo: this, properties: ["showLayer"], control: () => (_jsx(Layer, { open: this.showLayer, showCloseButton: true, onClose: this.onClose, renderUI: () => (_jsx(ClickAwayListener, Object.assign({ onClickAway: () => {
                        this.showLayer = false;
                        StateManager.propertyChanged(this, "showLayer");
                    } }, { children: _jsx("div", { children: _jsx(FileUploadLayer, { files: files, addFiles: this.addFiles, onDelete: this.deleteFile, showFileName: this.showFileName, showFileSize: this.showFileSize, showPreview: this.showPreview, filesLimit: this.filesLimit, onClose: this.onClose, title: "Upload Files:" }, void 0) }, void 0) }), void 0)) }, void 0)) }, void 0));
    }
    getDesignValidationIssues() {
        return [];
    }
    getRuntimeValidationIssues() {
        return [];
    }
    getAddedData() {
        return;
    }
}
//# sourceMappingURL=BaseFileControl.js.map