import{withInstall as e}from"../_util/type.mjs";import t from"../_util/classNames.mjs";import n from"../_util/omit.mjs";import r from"../_util/throttleByAnimationFrame.mjs";import i from"../config-provider/hooks/useConfigInject.mjs";import a from"../vc-resize-observer/index.mjs";import o from"./style/index.mjs";import{addObserveTarget as s,getFixedBottom as c,getFixedTop as l,getTargetRect as u,removeObserveTarget as d}from"./utils.mjs";import{computed as f,createVNode as p,defineComponent as m,getCurrentInstance as h,onMounted as g,onUnmounted as _,onUpdated as v,reactive as y,shallowRef as b,watch as x}from"vue";function S(){return typeof window<`u`?window:null}var C=function(e){return e[e.None=0]=`None`,e[e.Prepare=1]=`Prepare`,e}(C||{});function w(){return{offsetTop:Number,offsetBottom:Number,target:{type:Function,default:S},prefixCls:String,onChange:Function,onTestUpdatePosition:Function}}var T=e(m({compatConfig:{MODE:3},name:`AAffix`,inheritAttrs:!1,props:w(),setup(e,{slots:m,emit:S,expose:w,attrs:T}){let E=b(),D=b(),O=y({affixStyle:void 0,placeholderStyle:void 0,status:C.None,lastAffix:!1,prevTarget:null,timeout:null}),k=h(),A=f(()=>e.offsetBottom===void 0&&e.offsetTop===void 0?0:e.offsetTop),j=f(()=>e.offsetBottom),M=()=>{let{status:t,lastAffix:n}=O,{target:r}=e;if(t!==C.Prepare||!D.value||!E.value||!r)return;let i=r();if(!i)return;let a={status:C.None},o=u(E.value);if(o.top===0&&o.left===0&&o.width===0&&o.height===0)return;let s=u(i),d=l(o,s,A.value),f=c(o,s,j.value);if(!(o.top===0&&o.left===0&&o.width===0&&o.height===0)){if(d!==void 0){let e=`${o.width}px`,t=`${o.height}px`;a.affixStyle={position:`fixed`,top:d,width:e,height:t},a.placeholderStyle={width:e,height:t}}else if(f!==void 0){let e=`${o.width}px`,t=`${o.height}px`;a.affixStyle={position:`fixed`,bottom:f,width:e,height:t},a.placeholderStyle={width:e,height:t}}a.lastAffix=!!a.affixStyle,n!==a.lastAffix&&S(`change`,a.lastAffix),Object.assign(O,a)}},N=()=>{Object.assign(O,{status:C.Prepare,affixStyle:void 0,placeholderStyle:void 0})},P=r(()=>{N()}),F=r(()=>{let{target:t}=e,{affixStyle:n}=O;if(t&&n){let e=t();if(e&&E.value){let t=u(e),r=u(E.value),i=l(r,t,A.value),a=c(r,t,j.value);if(i!==void 0&&n.top===i||a!==void 0&&n.bottom===a)return}}N()});w({updatePosition:P,lazyUpdatePosition:F}),x(()=>e.target,e=>{let t=e?.()||null;O.prevTarget!==t&&(d(k),t&&(s(t,k),P()),O.prevTarget=t)}),x(()=>[e.offsetTop,e.offsetBottom],P),g(()=>{let{target:t}=e;t&&(O.timeout=setTimeout(()=>{s(t(),k),P()}))}),v(()=>{M()}),_(()=>{clearTimeout(O.timeout),d(k),P.cancel(),F.cancel()});let{prefixCls:I}=i(`affix`,e),[L,R]=o(I);return()=>{let{affixStyle:r,placeholderStyle:i,status:o}=O,s=t({[I.value]:r,[R.value]:!0}),c=n(e,[`prefixCls`,`offsetTop`,`offsetBottom`,`target`,`onChange`,`onTestUpdatePosition`]);return L(p(a,{onResize:P},{default:()=>[p(`div`,{...c,...T,ref:E,"data-measure-status":o},[r&&p(`div`,{style:i,"aria-hidden":`true`},null),p(`div`,{class:s,ref:D,style:r},[m.default?.()])])]}))}}}));export{w as affixProps,T as default};