var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef } from 'react';
import { ListItem } from '@material-ui/core';
import { NavLink } from 'react-router-dom';
const ListItemLinkComponent = forwardRef((props, ref) => (React.createElement(NavLink, Object.assign({ exact: true }, props, { innerRef: ref }))));
ListItemLinkComponent.displayName = 'ListItemLinkComponent';
export const AppMenuItemComponent = (props) => {
    const { link, tenantHref, params, isChild } = props, other = __rest(props
    // If link is not set return the ordinary ListItem
    , ["link", "tenantHref", "params", "isChild"])
    // If link is not set return the ordinary ListItem
    ;
    // If link is not set return the ordinary ListItem
    if (!link || typeof link !== 'string') {
        return React.createElement(ListItem, Object.assign({ button: true }, other, { dense: true }));
    }
    // The "to" pathname stays clean so normal (left-click) SPA navigation keeps a
    // tenant-free URL. New-tab intents (right-click, middle-click, ctrl/cmd-click)
    // use the anchor's href instead, so we swap in the tenant-carrying href just
    // in time on mousedown. React Router navigates left-clicks via "to" (not
    // href), so a dirtied href never leaks into the address bar.
    const swapHrefForNewTab = (e) => {
        if (!tenantHref)
            return;
        const opensNewTab = e.button === 1 || e.button === 2 || e.ctrlKey || e.metaKey;
        if (opensNewTab)
            e.currentTarget.setAttribute('href', tenantHref);
    };
    // Return a ListItem with a link component
    return (React.createElement(ListItem, Object.assign({ id: 'udpRecord-AppMenuItemComponent-' + params.label.replace(/\s+/g, ''), udprecordid: 'udpRecord-AppMenuItemComponent-' + params.label.replace(/\s+/g, ''), button: true, component: ListItemLinkComponent, to: {
            pathname: link,
            state: params
        }, onMouseDown: tenantHref ? swapHrefForNewTab : undefined }, other, { onClick: undefined, dense: true })));
};
//# sourceMappingURL=AppMenuItemComponent.js.map