import{i as e,n as t,t as n}from"./jsx-runtime-CXrijb2r.js";import{r}from"./core-DcH9fClu.js";import{n as i}from"./host-IZNQjG4L.js";var a=new Set([`http:`,`https:`]);function o(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;try{let e=new URL(t);return a.has(e.protocol)?e.toString():null}catch{return null}}function s(e){return!e.defaultPrevented&&e.button===0&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey}async function c(e){let t=o(e);if(!t)throw Error(`Unsupported external URL. Expected an absolute http or https URL.`);i()&&await r(`open_external_url`,{url:t})}async function l(e,t){return!s(e)||!i()?!1:(e.preventDefault(),await c(t),!0)}var u=e(t(),1),d=n(),f=(0,u.memo)(function({children:e,href:t,onClick:n,rel:r=`noreferrer noopener`,target:i=`_blank`,...a}){let s=o(t),c=(0,u.useCallback)(e=>{n?.(e),!(e.defaultPrevented||!s)&&l(e,s).catch(e=>{console.error(`Unable to open external URL ${s}:`,e)})},[s,n]);return s?(0,d.jsx)(`a`,{...a,href:s,onClick:c,rel:r,target:i,children:e}):(0,d.jsx)(`span`,{...a,children:e})});f.displayName=`ExternalLink`;export{f as t};