import * as React from "react";
import { useEffect, useState } from "react";
import { FEAGlobals } from "../../../common/Globals";
import glueFactory from "@interopio/desktop";
const DownloadIcon = () => (React.createElement("div", { className: "finsemble-icon" },
    React.createElement("svg", { width: "16", height: "34", viewBox: "9 -3 16 34", xmlns: "http://www.w3.org/2000/svg" },
        React.createElement("g", { fill: "none", fillRule: "evenodd" },
            React.createElement("g", { fill: "#FFF", fillRule: "nonzero" },
                React.createElement("path", { d: "M24 23.369a.57.57 0 0 1-.022.154c-.062.272-.33.477-.648.477H10.666c-.34 0-.622-.233-.657-.529-.009-.035-.009-.067-.009-.106v-2.773c0-.328.3-.592.661-.592.181 0 .348.067.467.174a.564.564 0 0 1 .194.418v2.22h11.36v-2.22c0-.328.3-.592.661-.592.18 0 .348.067.467.174.115.11.19.26.19.422v2.773z" }),
                React.createElement("path", { d: "m20.776 17.362-3.22 3.385c-.004.01-.013.014-.017.019a.746.746 0 0 1-.424.225c-.013 0-.026.004-.04.004-.026.005-.052.005-.078.005l-.074-.005c-.013 0-.027-.004-.04-.004a.733.733 0 0 1-.44-.244l-3.22-3.385a.825.825 0 0 1-.223-.57c0-.206.074-.412.223-.569a.743.743 0 0 1 1.083 0l1.935 2.035v-7.454c0-.441.345-.804.765-.804.21 0 .402.092.541.234.14.147.223.345.223.57v7.454l1.935-2.035a.743.743 0 0 1 1.084 0 .853.853 0 0 1-.013 1.14z" }))))));
/**
 * Spawns the download manager, which is a singleton.
 */
export const DownloadButton = ({ className, children }) => {
    const [glue, setGlue] = useState(null);
    const wrapperClasses = `finsemble-toolbar-button icon-only ${className || ""}`.trim();
    useEffect(() => {
        // If running in iocd then set up the glue library
        if (window.glue42gd) {
            glueFactory().then((myGlue) => {
                setGlue(myGlue);
            });
        }
    }, []);
    const clickEvent = () => {
        // When running in io.cd launch its download manager
        if (glue) {
            const app = glue.appManager.application("io-connect-download-manager");
            if (app) {
                app.start();
            }
        }
        else {
            FEAGlobals.FSBL.Clients.LauncherClient.spawn("Download Manager", {
                width: 400,
                height: 600,
                staggerPixels: 0,
            });
        }
    };
    return (React.createElement("span", { title: "Download Manager", className: wrapperClasses, role: "button", tabIndex: 0, onClick: clickEvent, onKeyDown: (e) => {
            if (e.key === "Enter") {
                clickEvent();
            }
        } }, children || React.createElement(DownloadIcon, null)));
};
//# sourceMappingURL=DownloadButton.js.map