import React, { forwardRef, useCallback, useContext } from 'react';
import classnames from 'classnames';
import { useMdmUiPath } from '../contexts/MdmModuleContext';
import { UrlGeneratorsContext } from '../contexts/UrlGeneratorsContext';
import { isControlOrCommandPressed } from '../helpers/events';
import { useStyles } from './styles';
export var PivotingUriLink = forwardRef(function (_a, ref) {
    var value = _a.value, attributeType = _a.attributeType, children = _a.children, className = _a.className, onClick = _a.onClick;
    var styles = useStyles();
    var generatePivotingUrl = useContext(UrlGeneratorsContext).generatePivotingUrl;
    var uiPath = useMdmUiPath();
    var url = generatePivotingUrl({ uiPath: uiPath, uri: attributeType.uri, value: JSON.stringify(value) });
    var handleClick = useCallback(function (e) {
        if (!isControlOrCommandPressed(e)) {
            onClick();
            e.preventDefault();
        }
        e.stopPropagation();
    }, [onClick]);
    return (React.createElement("a", { ref: ref, href: url, onClick: handleClick, className: classnames(styles.link, className) }, children));
});
PivotingUriLink.displayName = 'PivotingUriLink';
