import*as c from"react";import{Link as w,useNavigate as C}from"react-router-dom";import{getPathnameForLocale as N,withPathPrefix as P}from"@redocly/theme/core/utils";import{isAbsoluteUrl as _}from"../../shared/urls.js";import{useL10nConfig as R}from"./hooks/index.js";import{loadAndNavigate as b}from"./utils/loadAndNavigate.js";import{isForcedNavigationLinkClick as x}from"../utils.js";import{removeTrailingSlash as A}from"../../shared/utils";async function m(t){if(_(t))return;await(typeof window<"u"?window:global).__LOADER.tryLoad(t)}function S(t){const{to:e,children:f,className:u,style:a,innerRef:i,target:p,external:d,languageInsensitive:g,onClick:s,active:E,...L}=t,r={className:u,children:f,target:p||(d?"_blank":"_self"),rel:"noreferrer",onClick:s,...L},{defaultLocale:h,locales:v,currentLocale:y}=R(),o=e.startsWith("#")?e:P(g?e:N(e,h,y,v)),n=o!=="/"?A(o):o,k=C();return typeof e=="string"&&e.match(/^(https?:\/\/|mailto:)/)?c.createElement("a",{...r,ref:i,style:a,href:e,onMouseOver:async()=>m(e)}):c.createElement(w,{...r,ref:i,style:a,to:n,onClick:l=>{s?.(),!x(l,r.target)&&(l.preventDefault(),b({navigate:k,to:n}))},onMouseOver:async()=>m(n)})}export{S as Link};
