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