import{c as w,d as y,r as D,Q as L,R as $,S as p,w as A,T as N,b as l,o as f,n as R,U,V as B,W as I,f as M}from"./index-CriPLLD7.js";import{L as Y}from"./index-Df5zok-J.js";const[C,r,F]=w("pull-refresh"),x=50,G=["pulling","loosing","success"],Q={disabled:Boolean,modelValue:Boolean,headHeight:f(x),successText:String,pullingText:String,loosingText:String,loadingText:String,pullDistance:R,successDuration:f(500),animationDuration:f(300)};var W=y({name:C,props:Q,emits:["change","refresh","update:modelValue"],setup(s,{emit:d,slots:o}){let u;const g=D(),T=D(),H=L(g),e=$({status:"normal",distance:0,duration:0}),i=p(),P=()=>{if(s.headHeight!==x)return{height:`${s.headHeight}px`}},h=()=>e.status!=="loading"&&e.status!=="success"&&!s.disabled,V=t=>{const a=+(s.pullDistance||s.headHeight);return t>a&&(t<a*2?t=a+(t-a)/2:t=a*1.5+(t-a*2)/4),Math.round(t)},n=(t,a)=>{const c=+(s.pullDistance||s.headHeight);e.distance=t,a?e.status="loading":t===0?e.status="normal":t<c?e.status="pulling":e.status="loosing",d("change",{status:e.status,distance:t})},m=()=>{const{status:t}=e;return t==="normal"?"":s[`${t}Text`]||F(t)},k=()=>{const{status:t,distance:a}=e;if(o[t])return o[t]({distance:a});const c=[];return G.includes(t)&&c.push(l("div",{class:r("text")},[m()])),t==="loading"&&c.push(l(Y,{class:r("loading")},{default:m})),c},E=()=>{e.status="success",setTimeout(()=>{n(0)},+s.successDuration)},v=t=>{u=B(H.value)===0,u&&(e.duration=0,i.start(t))},b=t=>{h()&&v(t)},_=t=>{if(h()){u||v(t);const{deltaY:a}=i;i.move(t),u&&a.value>=0&&i.isVertical()&&(I(t),n(V(a.value)))}},S=()=>{u&&i.deltaY.value&&h()&&(e.duration=+s.animationDuration,e.status==="loosing"?(n(+s.headHeight,!0),d("update:modelValue",!0),U(()=>d("refresh"))):n(0))};return A(()=>s.modelValue,t=>{e.duration=+s.animationDuration,t?n(+s.headHeight,!0):o.success||s.successText?E():n(0,!1)}),N("touchmove",_,{target:T}),()=>{var t;const a={transitionDuration:`${e.duration}ms`,transform:e.distance?`translate3d(0,${e.distance}px, 0)`:""};return l("div",{ref:g,class:r()},[l("div",{ref:T,class:r("track"),style:a,onTouchstartPassive:b,onTouchend:S,onTouchcancel:S},[l("div",{class:r("head"),style:P()},[k()]),(t=o.default)==null?void 0:t.call(o)])])}}});const q=M(W);export{q as P};
