import{defineComponent as D,ref as S,reactive as k,watch as x,nextTick as m,onMounted as P,onActivated as A,onDeactivated as E,onBeforeUnmount as F,createVNode as f,Transition as H,withDirectives as R,vShow as $}from"vue";import{VerticalAlignTopOutlined as j}from"@antsoo-lib/icons";import G from"../_util/getScroll.mjs";import I from"../_util/props-util/initDefaultProps.mjs";import L from"../_util/scrollTo.mjs";import M from"../_util/throttleByAnimationFrame.mjs";import{getTransitionProps as O}from"../_util/transition.mjs";import V from"../config-provider/hooks/useConfigInject.mjs";import N,{floatButtonPrefixCls as U}from"./FloatButton.mjs";import{useInjectFloatButtonGroupContext as q}from"./context.mjs";import{backTopProps as z}from"./interface.mjs";import J from"./style/index.mjs";const it=D({compatConfig:{MODE:3},name:"ABackTop",inheritAttrs:!1,props:I(z(),{visibilityHeight:400,target:()=>window,duration:450,type:"default",shape:"circle"}),setup(e,{slots:p,attrs:l,emit:v}){const{prefixCls:a,direction:d}=V(U,e),[T]=J(a),r=S(),g=k({visible:e.visibilityHeight===0,scrollEvent:null}),c=()=>r.value&&r.value.ownerDocument?r.value.ownerDocument:window,h=o=>{const{target:n=c,duration:t}=e;L(0,{getContainer:n,duration:t}),v("click",o)},i=M(o=>{const{visibilityHeight:n}=e,t=G(o.target);g.visible=t>=n}),s=()=>{const{target:o}=e,t=(o||c)();i({target:t}),t?.addEventListener("scroll",i)},u=()=>{const{target:o}=e,t=(o||c)();i.cancel(),t?.removeEventListener("scroll",i)};x(()=>e.target,()=>{u(),m(()=>{s()})}),P(()=>{m(()=>{s()})}),A(()=>{m(()=>{s()})}),E(()=>{u()}),F(()=>{u()});const w=q();return()=>{const{description:o,type:n,shape:t,tooltip:b,badge:B}=e,C={...l,shape:w?.shape.value||t,onClick:h,class:{[`${a.value}`]:!0,[`${l.class}`]:l.class,[`${a.value}-rtl`]:d.value==="rtl"},description:o,type:n,tooltip:b,badge:B},y=O("fade");return T(f(H,y,{default:()=>[R(f(N,{...C,ref:r},{icon:()=>p.icon?.()||f(j,null,null)}),[[$,g.visible]])]}))}}});export{it as default};
