import React from "react";
import async from "async";
import { camelCase } from "../../../../../common/util";
import { Actions as WorkspaceManagementMenuActions } from "../../../toolbar/workspaceManagementMenu/stores/workspaceManagementMenuStore";
import { WorkspaceManagementMenuStore } from "../../stores/UserPreferencesStore";
import { Checkbox } from "../../../common/Checkbox";
import { WorkspaceButton } from "../workspaces/WorkspaceButton";
import WorkspaceComponents from "../workspaces/WorkspaceComponents";
import WorkspaceItemList from "../workspaces/WorkspaceItemList";
import { FEAGlobals } from "../../../../../common/Globals";
import { WORKSPACE } from "../../../../../common/constants";
import { ConfigUtilInstance as ConfigUtils } from "../../../../../common/configUtil";
const WORKSPACE_PREFERENCES = {
    PERMANENT_WORKSPACES: "finsemble.servicesConfig.workspace.permanentWorkspaces",
    PROMPT_USER_ON_DIRTY_WORKSPACE: "finsemble.servicesConfig.workspace.promptUserOnDirtyWorkspace",
    DISCARD_UNSAVED_CHANGES: "finsemble.servicesConfig.workspace.discardUnsavedChanges",
    INITIAL_WORKSPACE_PREFERENCE: "finsemble.initialWorkspace",
};
export default class Workspaces extends React.Component {
    constructor(props) {
        var _a, _b, _c;
        super(props);
        // variable to save the WORKSPACE.WORKSPACE_UPDATED subscriber
        this.workspaceUpdatedSubscriber = { subscribeID: "", topic: "" };
        this.state = {
            adding: false,
            editing: false,
            workspaceList: [],
            focusedWorkspace: "",
            workspaceToLoadOnStart: null,
            templateName: "",
            workspaceBeingEdited: "",
            focusedWorkspaceComponentList: [],
            initialAlwaysOnTop: (_a = FEAGlobals.finsembleWindow.windowOptions) === null || _a === void 0 ? void 0 : _a.alwaysOnTop,
            alwaysOnTop: (_b = FEAGlobals.finsembleWindow.windowOptions) === null || _b === void 0 ? void 0 : _b.alwaysOnTop,
            promptUserOnDirtyWorkspace: true,
            discardUnsavedChanges: false,
            permanentWorkspaces: [],
            activeWorkspace: ((_c = FEAGlobals.FSBL.Clients.WorkspaceClient.activeWorkspace) === null || _c === void 0 ? void 0 : _c.name) || "",
        };
        this.bindCorrectContext();
        this.addListeners();
    }
    resetState() {
        var _a;
        this.setState({
            adding: false,
            editing: false,
            focusedWorkspace: "",
            templateName: "",
            workspaceBeingEdited: "",
            activeWorkspace: ((_a = FEAGlobals.FSBL.Clients.WorkspaceClient.activeWorkspace) === null || _a === void 0 ? void 0 : _a.name) || "",
        });
    }
    bindCorrectContext() {
        this.deleteWorkspace = this.deleteWorkspace.bind(this);
        this.addListeners = this.addListeners.bind(this);
        this.setWorkspaceList = this.setWorkspaceList.bind(this);
        this.onDragEnd = this.onDragEnd.bind(this);
        this.startEditingWorkspace = this.startEditingWorkspace.bind(this);
        this.renameWorkspace = this.renameWorkspace.bind(this);
        this.cancelEdit = this.cancelEdit.bind(this);
        this.setWorkspaceToLoadOnStart = this.setWorkspaceToLoadOnStart.bind(this);
        this.setUIPreferencesState = this.setUIPreferencesState.bind(this);
        this.exportWorkspace = this.exportWorkspace.bind(this);
        this.handleButtonClicks = this.handleButtonClicks.bind(this);
        this.getFocusedWorkspaceComponentList = this.getFocusedWorkspaceComponentList.bind(this);
        this.changePreferencesAlwaysOnTop = this.changePreferencesAlwaysOnTop.bind(this);
        this.openFileDialog = this.openFileDialog.bind(this);
        this.preferencesFocused = this.preferencesFocused.bind(this);
        this.setFocusedWorkspace = this.setFocusedWorkspace.bind(this);
        this.toggleDiscardUnsavedChanges = this.toggleDiscardUnsavedChanges.bind(this);
        this.togglePromptUserOnDirtyWorkspace = this.togglePromptUserOnDirtyWorkspace.bind(this);
        this.setPermanentWorkspaces = this.setPermanentWorkspaces.bind(this);
    }
    setWorkspaceList(err, data) {
        if (!data)
            return;
        this.setState({
            workspaceList: data.value,
        });
    }
    setPermanentWorkspaces(err, config) {
        FEAGlobals.FSBL.Clients.Logger.system.log("Workspaces new permanentWorkspaces config", config);
        const { permanentWorkspaces } = config.value.workspace;
        if (permanentWorkspaces && Array.isArray(permanentWorkspaces)) {
            this.setState({
                permanentWorkspaces: permanentWorkspaces,
            });
        }
    }
    addListeners() {
        this.props.addListener({ field: "WorkspaceList" }, this.setWorkspaceList);
        this.props.addListener({ field: "preferences" }, this.setUIPreferencesState);
        FEAGlobals.FSBL.Clients.WorkspaceClient.addEventListener("save-complete", this.getFocusedWorkspaceComponentList);
        // Configuration listeners to update the WSM
        FEAGlobals.FSBL.Clients.ConfigClient.addListener({ field: WORKSPACE_PREFERENCES.PERMANENT_WORKSPACES }, this.setPermanentWorkspaces);
        // updates the active workspace
        this.workspaceUpdatedSubscriber = FEAGlobals.FSBL.Clients.RouterClient.subscribe(WORKSPACE.WORKSPACE_UPDATED, (err, response) => {
            this.setState({
                activeWorkspace: response.data.activeWorkspace.name,
            });
        });
    }
    /**
     * Sets the windowOptions.alwaysOnTop to the value supplied. The preferences component should
     * not be always on top when a file dialog is open.
     * @param {boolean} alwaysOnTop The value to set FEAGlobals.finsembleWindow.options.alwaysOnTop
     */
    changePreferencesAlwaysOnTop(alwaysOnTop) {
        // The initialAlwaysOnTop check is to prevent making a component be alwaysOnTop when the
        // client may have set it to alwaysOnTop:false in the config. If that's the case, it should
        // never set its alwaysOnTop to true and should always remain unchanged
        if (this.state.initialAlwaysOnTop) {
            FEAGlobals.FSBL.Clients.WindowClient.setAlwaysOnTop(alwaysOnTop, () => {
                this.setState({
                    alwaysOnTop,
                });
            });
        }
    }
    onDragEnd({ oldIndex, newIndex }) {
        let workspaces = JSON.parse(JSON.stringify(this.state.workspaceList));
        let workspaceToMove = JSON.parse(JSON.stringify(workspaces[oldIndex]));
        workspaces.splice(oldIndex, 1);
        workspaces.splice(newIndex, 0, workspaceToMove);
        this.setState({
            workspaceList: workspaces,
        });
        WorkspaceManagementMenuStore === null || WorkspaceManagementMenuStore === void 0 ? void 0 : WorkspaceManagementMenuStore.Dispatcher.dispatch({
            actionType: "reorderWorkspace",
            data: { oldIndex, newIndex },
        });
    }
    // returns all the component types of a template definition to display to user for additional info. If multiple components with same type, then instead of listing each
    // individually, only one entry will be returned with the count in parentheses.
    getComponentTypes(templateObject) {
        FEAGlobals.FSBL.Clients.Logger.system.debug("getComponentTypes templateObject", templateObject);
        let componentType;
        let componentMap = {};
        let annotatedComponentList = [];
        for (let i = 0; i < templateObject.windows.length; i++) {
            const windowData = templateObject.windowData[i];
            FEAGlobals.FSBL.Clients.Logger.system.debug("getComponentTypes loop", windowData);
            componentType = "Unknown Component";
            if (windowData) {
                // current assimilation doesn't fill in windowData, so in this case use "Unknown Component" for component type
                componentType = windowData.componentType || windowData.customData.component.type;
            }
            else {
                componentType = "Unknown Component";
            }
            if (!componentMap[componentType]) {
                componentMap[componentType] = 1;
            }
            else {
                componentMap[componentType]++;
            }
        }
        const componentTypes = Object.keys(componentMap);
        for (let i = 0; i < componentTypes.length; i++) {
            let annotatedName = componentTypes[i];
            let identicalCount = componentMap[componentTypes[i]];
            if (identicalCount > 1) {
                annotatedName = `${annotatedName} (${identicalCount})`;
            }
            annotatedComponentList.push(annotatedName);
        }
        FEAGlobals.FSBL.Clients.Logger.system.debug("getComponentTypes", annotatedComponentList);
        return annotatedComponentList;
    }
    setFocusedWorkspace(workspace) {
        this.setState({
            focusedWorkspace: workspace,
        }, () => this.getFocusedWorkspaceComponentList());
    }
    cancelEdit() {
        if (this.state.adding) {
            let { workspaceList } = this.state;
            workspaceList.pop();
            this.setFocusedWorkspace("");
            this.setState({
                workspaceList: workspaceList,
            });
        }
        this.setState({
            editing: false,
            adding: false,
            workspaceBeingEdited: "",
        });
    }
    renameWorkspace(newName) {
        let oldName = this.state.workspaceBeingEdited;
        if (oldName === "") {
            return this.cancelEdit();
        }
        if (newName === oldName || newName.trim() === "")
            return this.cancelEdit();
        let newNameCamelCase = camelCase(newName);
        if (this.state.workspaceList.some((workspace) => camelCase(workspace.name) === newNameCamelCase)) {
            let notification = new FEAGlobals.FSBL.Clients.NotificationClient.Notification();
            notification.source = "Finsemble";
            notification.title = "Workspace renaming";
            notification.details = `Sorry, unable to rename workspace to "${newName}". Please use another name.`;
            FEAGlobals.FSBL.Clients.NotificationClient.notify(notification);
            return this.cancelEdit();
        }
        let updatedWorkspaceList = this.state.workspaceList;
        let index = updatedWorkspaceList.findIndex((el) => el.name === oldName);
        // Set state locally so that the text doesn't change when the input field unmounts.
        if (index !== -1) {
            updatedWorkspaceList[index].name = newName;
            this.setState({
                workspaceList: updatedWorkspaceList,
            });
        }
        WorkspaceManagementMenuStore === null || WorkspaceManagementMenuStore === void 0 ? void 0 : WorkspaceManagementMenuStore.Dispatcher.dispatch({
            actionType: "renameWorkspace",
            data: {
                oldName: oldName,
                newName: newName,
            },
        });
        if (this.state.workspaceToLoadOnStart === oldName) {
            this.setState({
                focusedWorkspace: newName,
            }, () => {
                this.setWorkspaceToLoadOnStart(() => {
                    this.cancelEdit();
                });
            });
        }
        else {
            this.cancelEdit();
        }
    }
    startEditingWorkspace(e, workspaceName = this.state.focusedWorkspace) {
        // without preventing this event from reaching the finsemble draggable,
        // the editor will lose focus and you won't be able to rename your workspaces
        e.stopPropagation();
        this.setState({
            editing: true,
            focusedWorkspace: workspaceName,
            workspaceBeingEdited: workspaceName,
        });
    }
    startExportingTemplate() {
        WorkspaceManagementMenuStore === null || WorkspaceManagementMenuStore === void 0 ? void 0 : WorkspaceManagementMenuStore.Dispatcher.dispatch({
            actionType: "exportWorkspace",
            data: {
                name: this.state.focusedWorkspace,
            },
        });
    }
    startImportingTemplate() {
        WorkspaceManagementMenuStore === null || WorkspaceManagementMenuStore === void 0 ? void 0 : WorkspaceManagementMenuStore.Dispatcher.dispatch({
            actionType: "importTemplate",
            data: {
                name: this.state.templateName,
            },
        });
    }
    deleteWorkspace(workspaceName = this.state.focusedWorkspace) {
        this.resetState();
        const removeWorkspaceFromList = (wasDeleted) => {
            if (wasDeleted) {
                let workspaceListCopy = [...this.state.workspaceList];
                workspaceListCopy = workspaceListCopy.filter((workspace) => workspace.name !== workspaceName);
                // If we just removed the workspace configured to be loaded at startup
                // we need to unset initial workspace preference
                if (workspaceName === this.state.workspaceToLoadOnStart) {
                    this.setState({ workspaceToLoadOnStart: null }, () => FEAGlobals.FSBL.Clients.ConfigClient.unsetPreference({
                        field: WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE,
                    }));
                }
                this.setState({ workspaceList: workspaceListCopy });
            }
        };
        const data = {
            name: workspaceName,
        };
        WorkspaceManagementMenuActions.removeWorkspace(data, removeWorkspaceFromList);
    }
    setUIPreferencesState(err, data) {
        var _a;
        const { value } = data || {};
        if (!value)
            return;
        this.setState({
            workspaceToLoadOnStart: data.value[WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE],
            focusedWorkspace: data.value[WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE] || this.state.workspaceList[0].name,
            promptUserOnDirtyWorkspace: data.value[WORKSPACE_PREFERENCES.PROMPT_USER_ON_DIRTY_WORKSPACE],
            discardUnsavedChanges: (_a = data.value[WORKSPACE_PREFERENCES.DISCARD_UNSAVED_CHANGES]) !== null && _a !== void 0 ? _a : false,
        });
    }
    componentDidMount() {
        // load preferences values from config and set component state on mount
        FEAGlobals.FSBL.Clients.ConfigClient.getMultiple([
            WORKSPACE_PREFERENCES.PROMPT_USER_ON_DIRTY_WORKSPACE.split("."),
            WORKSPACE_PREFERENCES.DISCARD_UNSAVED_CHANGES.split("."),
            WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE.split("."),
            WORKSPACE_PREFERENCES.PERMANENT_WORKSPACES.split("."),
        ], (err, values) => {
            var _a, _b, _c, _d;
            if (err) {
                FEAGlobals.FSBL.Clients.Logger.system.info("componentDidMount.getValues error", err);
            }
            if (values) {
                this.setState({
                    workspaceToLoadOnStart: values[WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE],
                    focusedWorkspace: (_a = values[WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE]) !== null && _a !== void 0 ? _a : (_b = FEAGlobals.FSBL.Clients.WorkspaceClient.activeWorkspace) === null || _b === void 0 ? void 0 : _b.name,
                    promptUserOnDirtyWorkspace: values[WORKSPACE_PREFERENCES.PROMPT_USER_ON_DIRTY_WORKSPACE],
                    discardUnsavedChanges: (_c = values[WORKSPACE_PREFERENCES.DISCARD_UNSAVED_CHANGES]) !== null && _c !== void 0 ? _c : false,
                    permanentWorkspaces: (_d = values[WORKSPACE_PREFERENCES.PERMANENT_WORKSPACES]) !== null && _d !== void 0 ? _d : [],
                }, () => this.getFocusedWorkspaceComponentList());
            }
        });
        this.props.getValue(["WorkspaceList"], (err, data) => {
            if (data && data.length) {
                this.setState({
                    workspaceList: data,
                    // set the first workspace from list as focused
                    focusedWorkspace: data[0].name,
                });
            }
        });
    }
    componentWillUnmount() {
        this.props.removeListener({ field: "preferences" }, this.setUIPreferencesState);
        FEAGlobals.FSBL.Clients.ConfigClient.removeListener({ field: WORKSPACE_PREFERENCES.PERMANENT_WORKSPACES }, this.setPermanentWorkspaces);
        FEAGlobals.FSBL.Clients.RouterClient.unsubscribe(this.workspaceUpdatedSubscriber);
    }
    setPreference(field, value, cb) {
        FEAGlobals.FSBL.Clients.ConfigClient.setPreference({
            field,
            value,
        }, (err) => {
            if (err) {
                console.error(err);
            }
            if (cb) {
                cb();
            }
        });
    }
    setWorkspaceToLoadOnStart(eventOrCb) {
        if (!this.state.focusedWorkspace)
            return;
        if (this.state.focusedWorkspace === this.state.workspaceToLoadOnStart) {
            this.setState({ workspaceToLoadOnStart: null }, () => this.setPreference(WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE, null));
        }
        else {
            this.setState({
                workspaceToLoadOnStart: this.state.focusedWorkspace,
            }, () => this.setPreference(WORKSPACE_PREFERENCES.INITIAL_WORKSPACE_PREFERENCE, this.state.focusedWorkspace));
        }
        if (typeof eventOrCb === "function") {
            eventOrCb();
        }
    }
    openFileDialog() {
        // Set alwaysOnTop to false and add an event listener on the window. When focus is regained
        // then reset always on top
        this.changePreferencesAlwaysOnTop(false);
        FEAGlobals.finsembleWindow.addEventListener("focused", this.preferencesFocused);
        let inputElement = document.getElementById("file-input");
        inputElement === null || inputElement === void 0 ? void 0 : inputElement.addEventListener("change", this.importWorkspace, false);
        inputElement === null || inputElement === void 0 ? void 0 : inputElement.click();
    }
    /**
     * If the event is being listened to, when the preferences component is focused
     * it will set always on top to true, and remove the event listener
     *
     * This is to handle bringing alwaysOnTop back to true when file dialogs are closed
     * without changes (also handles bringing back to front after exporting)
     */
    preferencesFocused() {
        FEAGlobals.finsembleWindow.removeEventListener("focused", this.preferencesFocused);
        this.changePreferencesAlwaysOnTop(true);
    }
    importWorkspace(evt) {
        let inputElement = document.getElementById("file-input");
        inputElement === null || inputElement === void 0 ? void 0 : inputElement.removeEventListener("change", this.importWorkspace);
        const { files } = evt.target; // FileList object
        function loadFile(file, done) {
            const reader = new FileReader();
            let fileName = evt.target.value;
            // When the file info is loaded, we get into here..
            reader.onload = function (e) {
                var _a;
                try {
                    fileName = fileName.split("\\");
                    fileName = fileName[fileName.length - 1].replace(".json", "");
                    let workspaceTemplateDefinition = JSON.parse((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.result);
                    let templateName = Object.keys(workspaceTemplateDefinition.workspaceTemplates)[0];
                    if (fileName !== templateName) {
                        // We want the file name to overwrite the name of the workspace that was saved as the template..
                        workspaceTemplateDefinition.workspaceTemplates[fileName] =
                            workspaceTemplateDefinition.workspaceTemplates[templateName];
                        delete workspaceTemplateDefinition.workspaceTemplates[templateName];
                    }
                    workspaceTemplateDefinition.workspaceTemplates[fileName].name = fileName;
                    FEAGlobals.FSBL.Clients.WorkspaceClient.import({
                        workspaceJSONDefinition: workspaceTemplateDefinition.workspaceTemplates,
                        force: false,
                    }, (err) => {
                        if (err) {
                            FEAGlobals.FSBL.Clients.Logger.system.info("addWorkspaceTemplateDefinition error", err);
                            FEAGlobals.FSBL.UserNotification.alert("system", "ALWAYS", "FSBL-Workspace-Import-Error", "The workspace can't be imported and it could be corrupt. Check the Central Logger for any errors.");
                        }
                        done();
                    });
                }
                catch (error) {
                    FEAGlobals.FSBL.Clients.Logger.system.error(error);
                    FEAGlobals.FSBL.UserNotification.alert("system", "ALWAYS", "FSBL-Workspace-Import-Error", "The workspace can't be imported and it could be corrupt. Check the Central Logger for any errors.");
                    done();
                }
            };
            // Read in the image file as a data URL.
            reader.readAsText(file);
        }
        async.each(files, loadFile, () => {
            // Clear out files. so if the user imports the same  file back-to-back, the event will fire.
            if (inputElement === null || inputElement === void 0 ? void 0 : inputElement.value) {
                inputElement.value = "";
            }
            FEAGlobals.FSBL.Clients.Logger.system.info("Workspaces imported");
        });
    }
    exportWorkspace() {
        if (this.state.focusedWorkspace === "")
            return;
        const doExport = () => {
            FEAGlobals.FSBL.Clients.WorkspaceClient.export({ workspaceName: this.state.focusedWorkspace }, (err, workspaceDefinition) => {
                if (err) {
                    FEAGlobals.FSBL.Clients.Logger.system.error("export error", err);
                }
                else {
                    // We're saving using a routine initially created for templates. The outcome is the same and it probably should have just been "Save to file". This bool is to allow it to save.
                    ConfigUtils.promptAndSaveJSONToLocalFile(this.state.focusedWorkspace, {
                        workspaceTemplates: workspaceDefinition,
                    });
                }
            });
        };
        // Set alwaysOnTop to false and add an event listener on the window. When focus is regained
        // then reset always on top
        this.changePreferencesAlwaysOnTop(false);
        FEAGlobals.finsembleWindow.addEventListener("focused", this.preferencesFocused);
        // If we're autosaving, autosave, then export.
        FEAGlobals.FSBL.Clients.ConfigClient.get(["finsemble", "preferences", "workspaceService", "promptUserOnDirtyWorkspace"], (err, data) => {
            var _a, _b, _c, _d;
            // default to false.
            let PROMPT_ON_SAVE = data === null ? false : data;
            if (!PROMPT_ON_SAVE) {
                let activeName = ((_d = (_c = (_b = (_a = FEAGlobals.FSBL) === null || _a === void 0 ? void 0 : _a.Clients) === null || _b === void 0 ? void 0 : _b.WorkspaceClient) === null || _c === void 0 ? void 0 : _c.activeWorkspace) === null || _d === void 0 ? void 0 : _d.name) || "";
                return FEAGlobals.FSBL.Clients.WorkspaceClient.saveAs({
                    name: activeName,
                    force: true,
                }, () => {
                    doExport();
                });
            }
            doExport();
        });
    }
    handleButtonClicks(e) {
        if (this.state.adding || this.state.editing) {
            e.preventDefault();
        }
    }
    async getFocusedWorkspaceComponentList() {
        let { focusedWorkspace } = this.state;
        if (focusedWorkspace === "")
            return [];
        const workspaceDefinition = (await FEAGlobals.FSBL.Clients.WorkspaceClient.export({ workspaceName: focusedWorkspace }, () => { }));
        if (workspaceDefinition) {
            const workspaceComponents = this.getComponentTypes(workspaceDefinition[focusedWorkspace]);
            if (workspaceComponents) {
                this.setState({
                    focusedWorkspaceComponentList: workspaceComponents,
                });
            }
        }
    }
    toggleDiscardUnsavedChanges() {
        const newValue = !this.state.discardUnsavedChanges;
        this.setState({
            discardUnsavedChanges: newValue,
        }, () => this.setPreference(WORKSPACE_PREFERENCES.DISCARD_UNSAVED_CHANGES, newValue));
    }
    togglePromptUserOnDirtyWorkspace() {
        const newValue = !this.state.promptUserOnDirtyWorkspace;
        this.setState({
            promptUserOnDirtyWorkspace: newValue,
            discardUnsavedChanges: newValue ? false : this.state.discardUnsavedChanges,
        }, () => {
            this.setPreference(WORKSPACE_PREFERENCES.PROMPT_USER_ON_DIRTY_WORKSPACE, newValue);
            if (newValue) {
                this.setPreference(WORKSPACE_PREFERENCES.DISCARD_UNSAVED_CHANGES, false);
            }
        });
    }
    render() {
        var _a, _b, _c, _d;
        let deleteButtonClasses = "individual-workspace-action delete-workspace", renameButtonClasses = "individual-workspace-action", allowDelete = true, allowExport = true, allowRename = true, allowImport = true, deleteTooltip = "Delete";
        if (this.state.focusedWorkspace === ((_d = (_c = (_b = (_a = FEAGlobals.FSBL) === null || _a === void 0 ? void 0 : _a.Clients) === null || _b === void 0 ? void 0 : _b.WorkspaceClient) === null || _c === void 0 ? void 0 : _c.activeWorkspace) === null || _d === void 0 ? void 0 : _d.name)) {
            deleteButtonClasses = `${deleteButtonClasses} disabled-individual-workspace-action`;
        }
        if (this.state.focusedWorkspace === "") {
            renameButtonClasses = `${renameButtonClasses} disabled-individual-workspace-action`;
            deleteButtonClasses = `${deleteButtonClasses} disabled-individual-workspace-action`;
            deleteTooltip = "No workspace selected";
            allowRename = false;
            allowExport = false;
            allowDelete = false;
        }
        if (this.state.adding || this.state.editing) {
            renameButtonClasses = `${renameButtonClasses} disabled-button`;
            deleteButtonClasses = `${deleteButtonClasses} disabled-button`;
            allowDelete = false;
            allowExport = false;
            allowRename = false;
            allowImport = false;
        }
        let importTooltip = "Import workspace from file", exportTooltip = allowExport ? "Export selected workspace" : "No workspace selected", renameTooltip = allowRename ? "Rename" : "Cannot Edit";
        return (React.createElement("div", { style: { paddingLeft: 10 } },
            React.createElement("input", { style: { display: "none" }, type: "file", id: "file-input" }),
            React.createElement("div", { className: "complex-menu-content-row" },
                React.createElement("div", { className: "workspace-list-header-row" },
                    React.createElement("div", { className: "content-section-header workspace-list-header" })),
                React.createElement("div", { className: "content-section-wrapper" },
                    React.createElement(WorkspaceItemList, { onDragEnd: this.onDragEnd, workspaceList: this.state.workspaceList, allowDelete: allowDelete, deleteButtonClasses: deleteButtonClasses, deleteTooltip: deleteTooltip, workspaceToLoadOnStart: this.state.workspaceToLoadOnStart, focusedWorkspace: this.state.focusedWorkspace, editing: this.state.editing, adding: this.state.adding, renameWorkspace: this.renameWorkspace, addWorkspace: this.addWorkspace, cancelEdit: this.cancelEdit, setFocusedWorkspace: this.setFocusedWorkspace, renameTooltip: renameTooltip, renameButtonClasses: renameButtonClasses, allowRename: allowRename, handleButtonClicks: this.handleButtonClicks, startEditingWorkspace: this.startEditingWorkspace, deleteWorkspace: this.deleteWorkspace, permanentWorkspaces: this.state.permanentWorkspaces, activeWorkspaceName: this.state.activeWorkspace }),
                    React.createElement("div", { className: "workspace-extras" },
                        React.createElement(WorkspaceComponents, { focusedWorkspaceComponentList: this.state.focusedWorkspaceComponentList }),
                        React.createElement("div", { className: "workspace-action-buttons" },
                            React.createElement(WorkspaceButton, { title: importTooltip, onMouseDown: this.handleButtonClicks, onClick: allowImport ? this.openFileDialog : () => { }, type: "import" }),
                            React.createElement(WorkspaceButton, { title: exportTooltip, onMouseDown: this.handleButtonClicks, onClick: allowExport ? this.exportWorkspace : () => { }, type: "export" })))),
                React.createElement(Checkbox, { disabled: !this.state.focusedWorkspace, onClick: this.setWorkspaceToLoadOnStart, checked: !!this.state.focusedWorkspace && this.state.focusedWorkspace === this.state.workspaceToLoadOnStart, label: "Load this workspace on startup" }),
                React.createElement(React.Fragment, null, "\u00A0"),
                React.createElement(Checkbox, { onClick: this.togglePromptUserOnDirtyWorkspace, checked: this.state.promptUserOnDirtyWorkspace, label: "Prompt user to save changes on workspace close" }),
                React.createElement("span", { className: "indent-5px" },
                    React.createElement(Checkbox, { disabled: this.state.promptUserOnDirtyWorkspace, onClick: this.toggleDiscardUnsavedChanges, checked: this.state.discardUnsavedChanges, label: "Discard unsaved changes" })))));
    }
}
//# sourceMappingURL=Workspaces.js.map