import React from "react";
import { getStore } from "../stores/LauncherStore";
import AddNewFolder from "./AddNewFolder";
import { FEAGlobals } from "../../../../../../common/Globals";
export default class LeftNavBottomLinks extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            bottomEntries: [
                { name: "New App", click: "showAddAppForm" },
                {
                    name: "Restore Defaults",
                    icon: "ff-arrow-back",
                    click: "removeStore",
                },
            ],
        };
        // Display the menu item for adding a quick component only if the prop has been explicitly
        // turned on. This is passed all the way down from AdvancedAppLauncher.
        // DEPRECATED: Quick Components is deprecated and will be removed in a future version
        if (props.enableQuickComponents) {
            this.state.bottomEntries.push({
                name: "App Catalog",
                icon: "ff-list",
                click: "openAppMarket",
            });
        }
    }
    UNSAFE_componentWillMount() {
        // If user configures the advanced app launcher to use the app catalog, add app catalog button to the bottom entries of the
        // advanced app launcher menu.
        /**
         * @todo AppCatalog is deprecated. Remove in future release
         */
        FEAGlobals.finsembleWindow.getOptions((err, opts) => {
            var _a, _b;
            const useAppCatalog = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.customData) === null || _a === void 0 ? void 0 : _a.component) === null || _b === void 0 ? void 0 : _b.useAppCatalog;
            if (useAppCatalog) {
                this.setState((prevState) => {
                    return {
                        bottomEntries: [
                            ...prevState.bottomEntries,
                            {
                                name: "App Catalog",
                                icon: "ff-list",
                                click: "openAppMarket",
                            },
                        ],
                    };
                });
            }
        });
    }
    /**
     * Sets isFormVisible to true in store so that main component
     * renders the AddNewAppForm component or removes it
     */
    async showAddAppForm() {
        var _a;
        await ((_a = getStore()) === null || _a === void 0 ? void 0 : _a.set(["isFormVisible"], true, (error) => {
            error && console.log("Failed to set isFormVisible to true");
        }));
    }
    removeStore() {
        FEAGlobals.FSBL.Clients.DialogManager.open("YesNoDialog", {
            monitor: "primary",
            title: "Restore App Launcher?",
            question: "The application will restart and restore the app launcher to its default state.",
            showTimer: false,
            includeNegative: false,
            includeCancel: true,
            showCancelButton: true,
            showNegativeButton: false,
            affirmativeResponseLabel: "Restore",
        }, (err, response) => {
            const { choice } = response;
            if (choice) {
                switch (choice) {
                    case "affirmative":
                        FEAGlobals.FSBL.Clients.DistributedStoreClient.removeStore({ store: "Finsemble-AppLauncher-Store", global: true }, () => {
                            FEAGlobals.FSBL.restartApplication();
                        });
                        return;
                    case "negative":
                    case "cancel":
                    default:
                        return;
                }
            }
        });
    }
    render() {
        return (React.createElement("div", { className: "advanced-app-launcher-nav-bottom" },
            React.createElement(AddNewFolder, null),
            this.state.bottomEntries.map((entry, index) => {
                let handler = entry.click
                    ? this[entry.click] || this.props[entry.click]
                    : Function.prototype;
                let className = entry.icon ? `${entry.icon} complex-menu-action` : "ff-plus-2 complex-menu-action";
                return (React.createElement("div", { className: className, key: index, onClick: handler }, entry.name));
            })));
    }
}
//# sourceMappingURL=LeftNavBottomLinks.js.map