import{__exports as e}from"../../../../_virtual/link.js_commonjs-exports";import o from"../../node_modules/@babel/runtime/helpers/interopRequireWildcard.js";import t from"react";import"../next-server/lib/router/router.js";import"./router.js";import"./use-intersection.js";import{__exports as r}from"../../../../_virtual/router2.js_commonjs-exports";import{__exports as s}from"../../../../_virtual/router.js_commonjs-exports";import{__exports as n}from"../../../../_virtual/use-intersection.js_commonjs-exports";var c=o;e.__esModule=!0,e.default=void 0;var l=c(t),a=r,i=s,p=n;const f={};function u(e,o,t,r){if("undefined"==typeof window||!e)return;if(!(0,a.isLocalURL)(o))return;e.prefetch(o,t,r).catch((e=>{if("production"!==process.env.NODE_ENV)throw e}));const s=r&&void 0!==r.locale?r.locale:e&&e.locale;f[o+"%"+t+(s?"%"+s:"")]=!0}var d=function(e){if("production"!==process.env.NODE_ENV){function o(e){return new Error(`Failed prop type: The prop \`${e.key}\` expects a ${e.expected} in \`<Link>\`, but got \`${e.actual}\` instead.`+("undefined"!=typeof window?"\nOpen your browser's console to view the Component stack trace.":""))}const t={href:!0};Object.keys(t).forEach((t=>{if("href"===t&&(null==e[t]||"string"!=typeof e[t]&&"object"!=typeof e[t]))throw o({key:t,expected:"`string` or `object`",actual:null===e[t]?"null":typeof e[t]})}));const r={as:!0,replace:!0,scroll:!0,shallow:!0,passHref:!0,prefetch:!0,locale:!0};Object.keys(r).forEach((t=>{const r=typeof e[t];if("as"===t){if(e[t]&&"string"!==r&&"object"!==r)throw o({key:t,expected:"`string` or `object`",actual:r})}else if("locale"===t){if(e[t]&&"string"!==r)throw o({key:t,expected:"`string`",actual:r})}else if(("replace"===t||"scroll"===t||"shallow"===t||"passHref"===t||"prefetch"===t)&&null!=e[t]&&"boolean"!==r)throw o({key:t,expected:"`boolean`",actual:r})}));const s=l.default.useRef(!1);e.prefetch&&!s.current&&(s.current=!0,console.warn("Next.js auto-prefetches automatically based on viewport. The prefetch attribute is no longer needed. More: https://nextjs.org/docs/messages/prefetch-true-deprecated"))}const t=!1!==e.prefetch,r=(0,i.useRouter)(),s=r&&r.asPath||"/",{href:n,as:c}=l.default.useMemo((()=>{const[o,t]=(0,a.resolveHref)(s,e.href,!0);return{href:o,as:e.as?(0,a.resolveHref)(s,e.as):t||o}}),[s,e.href,e.as]);let{children:d,replace:h,shallow:m,scroll:y,locale:v}=e;"string"==typeof d&&(d=l.default.createElement("a",null,d));const j=l.Children.only(d),_=j&&"object"==typeof j&&j.ref,[w,x]=(0,p.useIntersection)({rootMargin:"200px"}),b=l.default.useCallback((e=>{w(e),_&&("function"==typeof _?_(e):"object"==typeof _&&(_.current=e))}),[_,w]);(0,l.useEffect)((()=>{const e=x&&t&&(0,a.isLocalURL)(n),o=void 0!==v?v:r&&r.locale,s=f[n+"%"+c+(o?"%"+o:"")];e&&!s&&u(r,n,c,{locale:o})}),[c,n,x,v,t,r]);const g={ref:b,onClick:e=>{j.props&&"function"==typeof j.props.onClick&&j.props.onClick(e),e.defaultPrevented||function(e,o,t,r,s,n,c,l){const{nodeName:i}=e.currentTarget;("A"!==i||!function(e){const{target:o}=e.currentTarget;return o&&"_self"!==o||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.nativeEvent&&2===e.nativeEvent.which}(e)&&(0,a.isLocalURL)(t))&&(e.preventDefault(),null==c&&(c=r.indexOf("#")<0),o[s?"replace":"push"](t,r,{shallow:n,locale:l,scroll:c}))}(e,r,n,c,h,m,y,v)},onMouseEnter:e=>{(0,a.isLocalURL)(n)&&(j.props&&"function"==typeof j.props.onMouseEnter&&j.props.onMouseEnter(e),u(r,n,c,{priority:!0}))}};if(e.passHref||"a"===j.type&&!("href"in j.props)){const e=void 0!==v?v:r&&r.locale,o=r&&r.isLocaleDomain&&(0,a.getDomainLocale)(c,e,r&&r.locales,r&&r.domainLocales);g.href=o||(0,a.addBasePath)((0,a.addLocale)(c,e,r&&r.defaultLocale))}return l.default.cloneElement(j,g)};e.default=d;
//# sourceMappingURL=link.js.map
