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