import React from "react";
import AppActionsMenu from "./AppActionsMenu";
import AppTagsList from "./AppTagsList";
import { FavoriteMaker } from "../../../../favorites/FavoriteMaker";
import { getStore } from "../stores/LauncherStore";
import storeActions from "../stores/StoreActions";
import { FEAGlobals } from "../../../../../../common/Globals";
/**
 * Used to make sure that a user is not waiting for component
 * to spawn after a double click, helps us prevent multiple
 * spawns for the same app.
 */
export default class AppDefinition extends React.Component {
    constructor(props) {
        super(props);
        this.onDragToFolder = this.onDragToFolder.bind(this);
        this.onItemClick = this.onItemClick.bind(this);
    }
    /**
     * Native HTML5 drag and drop
     **/
    onDragToFolder(event) {
        event.dataTransfer.setData("app", JSON.stringify(this.props.app));
    }
    /**
     * Spawns a component on click
     * @param {object} e The Synthetic React event
     *
     */
    async onItemClick() {
        var _a;
        const name = this.props.app.title || this.props.app.name;
        FEAGlobals.FSBL.Clients.LauncherClient.spawn(name.trim(), {
            addToWorkspace: true,
        });
        // Clear search text so it doesn't persist after app is opened
        if (storeActions.getSearchText()) {
            await ((_a = getStore()) === null || _a === void 0 ? void 0 : _a.set(["filterText"], null));
        }
    }
    render() {
        const { app } = this.props;
        const appId = app.title || app.name;
        const displayName = app.displayName || app.name;
        const tags = (app === null || app === void 0 ? void 0 : app.tags) || [];
        return (React.createElement("div", { onClick: this.onItemClick, className: "app-item link", draggable: "true", onDragStart: this.onDragToFolder },
            React.createElement("span", { className: "app-item-title" },
                React.createElement(FavoriteMaker, { id: appId, category: "Application", name: displayName, icon: app.icon }),
                React.createElement("span", { className: "app-name", title: displayName }, displayName)),
            tags.length > 0 && React.createElement(AppTagsList, { tags: tags }),
            React.createElement(AppActionsMenu, { app: app, folder: this.props.folder })));
    }
}
//# sourceMappingURL=AppDefinition.js.map