/*!
 * Copyright 2017 by ChartIQ, Inc.
 * All rights reserved.
 */
import React, { useRef, useEffect } from "react";
import { LinkerGroupsDeprecated } from "./LinkerGroupsDeprecated";
import { FEAGlobals } from "../../../common/Globals";
const LinkerButtonIcon = () => (React.createElement("svg", { width: "15px", height: "15px", viewBox: "2 1 13 13", xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink" },
    React.createElement("title", null, "Linker"),
    React.createElement("defs", null,
        React.createElement("path", { id: "prefix__b", d: "M17.925 15.425h-1v-2.5a2.5 2.5 0 0 0-5 0v2.5h-1v-2.5a3.5 3.5 0 1 1 7 0v2.5zm0 2v2.5a3.5 3.5 0 1 1-7 0v-2.5h1v2.5a2.5 2.5 0 0 0 5 0v-2.5h1zm-3.5-4a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-1 0v-5a.5.5 0 0 1 .5-.5z" }),
        React.createElement("filter", { id: "prefix__a", x: "-28.6%", y: "-7.1%", width: "157.1%", height: "128.6%" },
            React.createElement("feOffset", { dy: "1", in: "SourceAlpha", result: "shadowOffsetOuter1" }),
            React.createElement("feGaussianBlur", { in: "shadowOffsetOuter1", result: "shadowBlurOuter1", stdDeviation: ".5" }),
            React.createElement("feColorMatrix", { in: "shadowBlurOuter1", values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" }))),
    React.createElement("g", { transform: "rotate(45 22.289 4.682)", fillRule: "nonzero", fill: "none" },
        React.createElement("use", { filter: "url(#prefix__a)", xlinkHref: "#prefix__b" }),
        React.createElement("use", { xlinkHref: "#prefix__b" }))));
export const LinkerButtonDeprecated = ({ enableKeyboardShortcut = true }) => {
    const buttonRef = useRef(null);
    const showLinkerWindow = () => {
        let payload = {
            channels: FEAGlobals.FSBL.Clients.LinkerClient.getState().channels,
            windowIdentifier: FEAGlobals.FSBL.Clients.WindowClient.getWindowIdentifier(),
        };
        FEAGlobals.FSBL.Clients.RouterClient.query("Finsemble.LinkerWindow.SetActiveChannels", payload, () => {
            if (!buttonRef.current)
                return;
            const wi = {
                componentType: "LinkerWindow",
            };
            // The offset parent is needed so that the menu isn't shown relative to the icon.
            // The HTMLElement.offsetParent read-only property returns a reference to the object which is the closest (nearest in the containment hierarchy) positioned containing element.
            const linkerParent = buttonRef.current.offsetParent
                ? buttonRef.current.offsetParent
                : buttonRef.current.parentElement;
            if (!linkerParent)
                return;
            let params = {
                position: "relative",
                left: linkerParent.offsetLeft,
                top: linkerParent.offsetHeight,
                forceOntoMonitor: true,
                spawnIfNotFound: false,
            };
            // pass linkerbutton. If it's clicked while the menu is open, we let the blur occur.
            FEAGlobals.FSBL.Clients.LauncherClient.toggleWindowOnClick(buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current, wi, params);
        });
    };
    useEffect(() => {
        enableKeyboardShortcut &&
            window.addEventListener("keydown", (e) => {
                if (e.key === "l" && (e.ctrlKey || e.metaKey)) {
                    showLinkerWindow();
                }
            });
    }, []);
    return (React.createElement("div", { ref: buttonRef, title: "Link Data", className: "linkerSection" },
        React.createElement("div", { className: "fsbl-icon fsbl-linker", onClick: showLinkerWindow },
            React.createElement(LinkerButtonIcon, null)),
        React.createElement(LinkerGroupsDeprecated, null)));
};
//# sourceMappingURL=LinkerButtonDeprecated.js.map