import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import { RouterLink } from "../../../../../../components/index.js";
import { getMediaImage } from "../../../../../../components/Media/Image/utils.js";
import { LocationContext } from "../../../../../context/locationContext/index.js";
import { useAnalytics } from "../../../../../hooks/index.js";
import { NavigationArrow } from "../../../../../icons/index.js";
import { DefaultEventNames } from "../../../../../../models/index.js";
import { block, getLinkProps } from "../../../../../../utils/index.js";
import { ContentWrapper } from "../ContentWrapper/ContentWrapper.js";
import './NavigationLink.css';
const b = block('navigation-link');
export const NavigationLink = (props) => {
    const { hostname, Link } = React.useContext(LocationContext);
    const { url, text, icon, arrow, target, className, iconSize, urlTitle, analyticsEvents, onClick: onClickOrigin, ...rest } = props;
    const linkExtraProps = getLinkProps(url, hostname, target);
    const iconData = icon && getMediaImage(icon);
    const handleAnalytics = useAnalytics(DefaultEventNames.Link, url);
    const onClick = (e) => {
        handleAnalytics(analyticsEvents);
        if (onClickOrigin && e) {
            onClickOrigin?.(e);
        }
    };
    const classes = b(null, className);
    const content = (_jsxs(React.Fragment, { children: [_jsx(ContentWrapper, { text: text, icon: iconData, iconSize: iconSize }), arrow && _jsx(NavigationArrow, { className: b('arrow') })] }));
    if (linkExtraProps?.target || !Link) {
        return (_jsx("a", { href: url, title: urlTitle || text, className: classes, onClick: onClick, ...rest, ...linkExtraProps, children: content }));
    }
    else {
        return (_jsx(RouterLink, { href: url, passHref: true, children: _jsx("a", { role: "link", title: urlTitle || text, ...rest, className: classes, tabIndex: 0, onClick: onClick, onKeyDown: (e) => e.key === 'Enter' && onClick(), children: content }) }));
    }
};
//# sourceMappingURL=NavigationLink.js.map
