"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NavigationLink = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const components_1 = require("../../../../../../components/index.js");
const utils_1 = require("../../../../../../components/Media/Image/utils.js");
const locationContext_1 = require("../../../../../context/locationContext/index.js");
const hooks_1 = require("../../../../../hooks/index.js");
const icons_1 = require("../../../../../icons/index.js");
const models_1 = require("../../../../../../models/index.js");
const utils_2 = require("../../../../../../utils/index.js");
const ContentWrapper_1 = require("../ContentWrapper/ContentWrapper.js");
const b = (0, utils_2.block)('navigation-link');
const NavigationLink = (props) => {
    const { hostname, Link } = React.useContext(locationContext_1.LocationContext);
    const { url, text, icon, arrow, target, className, iconSize, urlTitle, analyticsEvents, onClick: onClickOrigin, ...rest } = props;
    const linkExtraProps = (0, utils_2.getLinkProps)(url, hostname, target);
    const iconData = icon && (0, utils_1.getMediaImage)(icon);
    const handleAnalytics = (0, hooks_1.useAnalytics)(models_1.DefaultEventNames.Link, url);
    const onClick = (e) => {
        handleAnalytics(analyticsEvents);
        if (onClickOrigin && e) {
            onClickOrigin?.(e);
        }
    };
    const classes = b(null, className);
    const content = ((0, jsx_runtime_1.jsxs)(React.Fragment, { children: [(0, jsx_runtime_1.jsx)(ContentWrapper_1.ContentWrapper, { text: text, icon: iconData, iconSize: iconSize }), arrow && (0, jsx_runtime_1.jsx)(icons_1.NavigationArrow, { className: b('arrow') })] }));
    if (linkExtraProps?.target || !Link) {
        return ((0, jsx_runtime_1.jsx)("a", { href: url, title: urlTitle || text, className: classes, onClick: onClick, ...rest, ...linkExtraProps, children: content }));
    }
    else {
        return ((0, jsx_runtime_1.jsx)(components_1.RouterLink, { href: url, passHref: true, children: (0, jsx_runtime_1.jsx)("a", { role: "link", title: urlTitle || text, ...rest, className: classes, tabIndex: 0, onClick: onClick, onKeyDown: (e) => e.key === 'Enter' && onClick(), children: content }) }));
    }
};
exports.NavigationLink = NavigationLink;
//# sourceMappingURL=NavigationLink.js.map
