import Navigation from "../../Utils/Navigation";
import React from "react";
const Link = (props) => {
    let children;
    if (typeof props.children === "string" ||
        typeof props.children === "number") {
        children = React.createElement("span", null, props.children);
    }
    else {
        children = props.children;
    }
    const linkProps = {};
    /*
     * Always set href when a destination is provided so the browser's native
     * right-click "Open in new tab" and Cmd/Ctrl+click behaviors work.
     */
    if (props.to) {
        linkProps["href"] = props.to.toString();
    }
    if (props.openInNewTab) {
        linkProps["target"] = "_blank";
    }
    const cursorClassName = props.to
        ? "cursor-pointer"
        : "cursor-default";
    return (React.createElement("a", Object.assign({ id: props.id, className: `${cursorClassName} ${props.className || ""}`, onMouseOver: props.onMouseOver, onMouseOut: props.onMouseOut, onMouseLeave: props.onMouseLeave, style: props.style, title: props.title, "aria-label": props.title, onAuxClick: (event) => {
            // middle click
            if (event.button === 1) {
                event.preventDefault();
                if (props.to) {
                    Navigation.navigate(props.to, {
                        openInNewTab: true,
                    });
                    if (props.onNavigateComplete) {
                        props.onNavigateComplete();
                    }
                }
            }
        }, onClick: (event) => {
            if (props.onClick) {
                props.onClick();
            }
            // Let the browser handle modifier-key clicks natively (open in new tab/window).
            if (event.metaKey || event.ctrlKey || event.shiftKey) {
                return;
            }
            if (props.openInNewTab) {
                // Let the browser handle the default behavior (open in new tab via href and target="_blank")
                return;
            }
            event.preventDefault();
            if (props.to) {
                Navigation.navigate(props.to);
            }
            if (props.onNavigateComplete) {
                props.onNavigateComplete();
            }
        } }, linkProps), children));
};
export default Link;
//# sourceMappingURL=Link.js.map