import*as f from"react";import d from"path";import{Link as P,useNavigate as _,useLocation as b}from"react-router-dom";import{getPathnameForLocale as x,withPathPrefix as A}from"@redocly/theme/core/utils";import{removeTrailingSlash as E}from"../../utils/url/remove-trailing-slash";import{normalizeRouteSlug as u}from"../../utils/path/normalize-route-slug";import{isAbsoluteUrl as O}from"../../utils/url/is-absolute-url";import{useL10nConfig as U}from"./hooks/index.js";import{loadAndNavigate as z}from"./utils/loadAndNavigate.js";import{isForcedNavigationLinkClick as D}from"../utils/utils.js";async function p(t,o){if(O(t))return;await(typeof window<"u"?window:global).__LOADER.tryLoad(t,void 0,o)}function H(t){const{to:o,children:a,className:h,style:i,innerRef:s,target:g,external:L,languageInsensitive:w,onClick:l,active:F,...v}=t,n={className:h,children:a,target:g||(L?"_blank":"_self"),rel:"noreferrer",onClick:l,...v},{defaultLocale:y,locales:k,currentLocale:R}=U(),C=b();let e=o;e.startsWith(".")&&(e=d.resolve(d.dirname(u(C.pathname)),u(o))),e=e.startsWith("#")?e:A(w?e:x(e,y,R,k));const r=e!=="/"?E(e):e,N=_(),c=typeof window<"u"?new URL(r,window.location.origin+window.location.pathname).search:void 0;return typeof o=="string"&&o.match(/^(https?:\/\/|mailto:)/)?f.createElement("a",{...n,ref:s,style:i,href:o,onMouseOver:async()=>p(o,c)}):f.createElement(P,{...n,ref:s,style:i,to:r,onClick:m=>{l?.(),!D(m,n.target)&&(m.preventDefault(),z({navigate:N,to:r}))},onMouseOver:async()=>p(r,c)})}export{H as Link};
