import{defineComponent as L,watch as x,nextTick as y,onMounted as A,onBeforeUnmount as j,createVNode as u}from"vue";import h from"../_util/classNames.mjs";import N from"../_util/props-util/initDefaultProps.mjs";import{objectType as P,anyType as $}from"../_util/type.mjs";import S from"../config-provider/hooks/useConfigInject.mjs";import{useInjectAnchor as b}from"./context.mjs";const w=()=>({prefixCls:String,href:String,title:$(),target:String,customTitleProps:P()}),H=L({compatConfig:{MODE:3},name:"AAnchorLink",inheritAttrs:!1,props:N(w(),{href:"#"}),slots:Object,setup(t,{slots:r,attrs:l}){let i=null;const{handleClick:k,scrollTo:p,unregisterLink:s,registerLink:a,activeLink:g}=b(),{prefixCls:C}=S("anchor",t),d=e=>{const{href:n}=t;k(e,{title:i,href:n}),p(n)};return x(()=>t.href,(e,n)=>{y(()=>{s(n),a(e)})}),A(()=>{a(t.href)}),j(()=>{s(t.href)}),()=>{const{href:e,target:n,title:c=r.title,customTitleProps:f={}}=t,o=C.value;i=typeof c=="function"?c(f):c;const m=g.value===e,T=h(`${o}-link`,{[`${o}-link-active`]:m},l.class),v=h(`${o}-link-title`,{[`${o}-link-title-active`]:m});return u("div",{...l,class:T},[u("a",{class:v,href:e,title:typeof i=="string"?i:"",target:n,onClick:d},[r.customTitle?r.customTitle(f):i]),r.default?.()])}}});export{w as anchorLinkProps,H as default};
