import{c as $,W as me,ab as P,_ as q,d as W,n as U,b3 as N,aa as V,r as w,u as fe,e as T,ac as oe,X as ae,aC as ve,Y as le,a as d,p as ce,H as X,b as _,t as he,m as be,a9 as ge,bC as Oe,w as L,bD as j,L as Te,ad as J,h as pe,z as Q,bE as ke,k as Ce}from"./index-74aaacd7.js";const[ye,g,Z]=$("picker"),ie=e=>e.find(a=>!a.disabled)||e[0];function xe(e,a){const o=e[0];if(o){if(Array.isArray(o))return"multiple";if(a.children in o)return"cascade"}return"default"}function B(e,a){a=q(a,0,e.length);for(let o=a;o=0;o--)if(!e[o].disabled)return o;return 0}const ee=(e,a,o)=>a!==void 0&&!!e.find(s=>s[o.value]===a);function G(e,a,o){const s=e.findIndex(f=>f[o.value]===a),c=B(e,s);return e[c]}function Ee(e,a,o){const s=[];let c={[a.children]:e},f=0;for(;c&&c[a.children];){const v=c[a.children],h=o.value[f];if(c=me(h)?G(v,h,a):void 0,!c&&v.length){const u=ie(v)[a.value];c=G(v,u,a)}f++,s.push(v)}return s}function we(e){const{transform:a}=window.getComputedStyle(e),o=a.slice(7,a.length-1).split(", ")[5];return Number(o)}function Pe(e){return P({text:"text",value:"value",children:"children"},e)}const te=200,ne=300,Se=15,[se,z]=$("picker-column"),ue=Symbol(se);var Ie=W({name:se,props:{value:U,fields:N(Object),options:V(),readonly:Boolean,allowHtml:Boolean,optionHeight:N(Number),swipeDuration:N(U),visibleOptionNum:N(U)},emits:["change","clickOption","scrollInto"],setup(e,{emit:a,slots:o}){let s,c,f,v,h;const u=w(),p=w(),r=w(0),m=w(0),C=fe(),y=()=>e.options.length,M=()=>e.optionHeight*(+e.visibleOptionNum-1)/2,k=i=>{let t=B(e.options,i);const n=-t*e.optionHeight,l=()=>{t>y()-1&&(t=B(e.options,i));const O=e.options[t][e.fields.value];O!==e.value&&a("change",O)};s&&n!==r.value?h=l:l(),r.value=n},b=()=>e.readonly||!e.options.length,A=i=>{s||b()||(h=null,m.value=te,k(i),a("clickOption",e.options[i]))},x=i=>q(Math.round(-i/e.optionHeight),0,y()-1),D=T(()=>x(r.value)),Y=(i,t)=>{const n=Math.abs(i/t);i=r.value+n/.003*(i<0?-1:1);const l=x(i);m.value=+e.swipeDuration,k(l)},S=()=>{s=!1,m.value=0,h&&(h(),h=null)},F=i=>{if(!b()){if(C.start(i),s){const t=we(p.value);r.value=Math.min(0,t-M())}m.value=0,c=r.value,f=Date.now(),v=c,h=null}},K=i=>{if(b())return;C.move(i),C.isVertical()&&(s=!0,ce(i,!0));const t=q(c+C.deltaY.value,-(y()*e.optionHeight),e.optionHeight),n=x(t);n!==D.value&&a("scrollInto",e.options[n]),r.value=t;const l=Date.now();l-f>ne&&(f=l,v=t)},I=()=>{if(b())return;const i=r.value-v,t=Date.now()-f;if(tSe){Y(i,t);return}const l=x(r.value);m.value=te,k(l),setTimeout(()=>{s=!1},0)},E=()=>{const i={height:`${e.optionHeight}px`};return e.options.map((t,n)=>{const l=t[e.fields.text],{disabled:O}=t,H=t[e.fields.value],re={role:"button",style:i,tabindex:O?-1:0,class:[z("item",{disabled:O,selected:H===e.value}),t.className],onClick:()=>A(n)},de={class:"van-ellipsis",[e.allowHtml?"innerHTML":"textContent"]:l};return d("li",re,[o.option?o.option(t,n):d("div",de,null)])})};return oe(ue),ae({stopMomentum:S}),ve(()=>{const i=s?Math.floor(-r.value/e.optionHeight):e.options.findIndex(l=>l[e.fields.value]===e.value),t=B(e.options,i),n=-t*e.optionHeight;s&&td("div",{ref:u,class:z(),onTouchstartPassive:F,onTouchend:I,onTouchcancel:I},[d("ul",{ref:p,style:{transform:`translate3d(0, ${r.value+M()}px, 0)`,transitionDuration:`${m.value}ms`,transitionProperty:m.value?"all":"none"},class:z("wrapper"),onTransitionend:S},[E()])])}});const[He]=$("picker-toolbar"),R={title:String,cancelButtonText:String,confirmButtonText:String},Me=["cancel","confirm","title","toolbar"],De=Object.keys(R);var Ne=W({name:He,props:R,emits:["confirm","cancel"],setup(e,{emit:a,slots:o}){const s=()=>{if(o.title)return o.title();if(e.title)return d("div",{class:[g("title"),"van-ellipsis"]},[e.title])},c=()=>a("cancel"),f=()=>a("confirm"),v=()=>{const u=e.cancelButtonText||Z("cancel");return d("button",{type:"button",class:[g("cancel"),X],onClick:c},[o.cancel?o.cancel():u])},h=()=>{const u=e.confirmButtonText||Z("confirm");return d("button",{type:"button",class:[g("confirm"),X],onClick:f},[o.confirm?o.confirm():u])};return()=>d("div",{class:g("toolbar")},[o.toolbar?o.toolbar():[v(),s(),h()]])}});const[_e,Ye]=$("picker-group"),Be=Symbol(_e);P({tabs:V(),activeTab:_(0),nextStepText:String},R);const Ve=P({loading:Boolean,readonly:Boolean,allowHtml:Boolean,optionHeight:_(44),showToolbar:he,swipeDuration:_(1e3),visibleOptionNum:_(6)},R),$e=P({},Ve,{columns:V(),modelValue:V(),toolbarPosition:be("top"),columnsFieldNames:Object});var Re=W({name:ye,props:$e,emits:["confirm","cancel","change","scrollInto","clickOption","update:modelValue"],setup(e,{emit:a,slots:o}){const s=w(),c=w(e.modelValue.slice(0)),{parent:f}=oe(Be),{children:v,linkChildren:h}=ge(ue);h();const u=T(()=>Pe(e.columnsFieldNames)),p=T(()=>Oe(e.optionHeight)),r=T(()=>xe(e.columns,u.value)),m=T(()=>{const{columns:t}=e;switch(r.value){case"multiple":return t;case"cascade":return Ee(t,u.value,c);default:return[t]}}),C=T(()=>m.value.some(t=>t.length)),y=T(()=>m.value.map((t,n)=>G(t,c.value[n],u.value))),M=T(()=>m.value.map((t,n)=>t.findIndex(l=>l[u.value.value]===c.value[n]))),k=(t,n)=>{if(c.value[t]!==n){const l=c.value.slice(0);l[t]=n,c.value=l}},b=()=>({selectedValues:c.value.slice(0),selectedOptions:y.value,selectedIndexes:M.value}),A=(t,n)=>{k(n,t),r.value==="cascade"&&c.value.forEach((l,O)=>{const H=m.value[O];ee(H,l,u.value)||k(O,H.length?H[0][u.value.value]:void 0)}),Q(()=>{a("change",P({columnIndex:n},b()))})},x=(t,n)=>{const l={columnIndex:n,currentOption:t};a("clickOption",P(b(),l)),a("scrollInto",l)},D=()=>{v.forEach(n=>n.stopMomentum());const t=b();return Q(()=>{a("confirm",t)}),t},Y=()=>a("cancel",b()),S=()=>m.value.map((t,n)=>d(Ie,{value:c.value[n],fields:u.value,options:t,readonly:e.readonly,allowHtml:e.allowHtml,optionHeight:p.value,swipeDuration:e.swipeDuration,visibleOptionNum:e.visibleOptionNum,onChange:l=>A(l,n),onClickOption:l=>x(l,n),onScrollInto:l=>{a("scrollInto",{currentOption:l,columnIndex:n})}},{option:o.option})),F=t=>{if(C.value){const n={height:`${p.value}px`},l={backgroundSize:`100% ${(t-p.value)/2}px`};return[d("div",{class:g("mask"),style:l},null),d("div",{class:[ke,g("frame")],style:n},null)]}},K=()=>{const t=p.value*+e.visibleOptionNum,n={height:`${t}px`};return d("div",{ref:s,class:g("columns"),style:n},[S(),F(t)])},I=()=>{if(e.showToolbar&&!f)return d(Ne,pe(J(e,De),{onConfirm:D,onCancel:Y}),J(o,Me))};L(m,t=>{t.forEach((n,l)=>{n.length&&!ee(n,c.value[l],u.value)&&k(l,ie(n)[u.value.value])})},{immediate:!0});let E;return L(()=>e.modelValue,t=>{!j(t,c.value)&&!j(t,E)&&(c.value=t.slice(0),E=t.slice(0))},{deep:!0}),L(c,t=>{j(t,e.modelValue)||(E=t.slice(0),a("update:modelValue",E))},{immediate:!0}),le("touchmove",ce,{target:s}),ae({confirm:D,getSelectedOptions:()=>y.value}),()=>{var t,n;return d("div",{class:g()},[e.toolbarPosition==="top"?I():null,e.loading?d(Te,{class:g("loading")},null):null,(t=o["columns-top"])==null?void 0:t.call(o),K(),(n=o["columns-bottom"])==null?void 0:n.call(o),e.toolbarPosition==="bottom"?I():null])}}});const Fe=Ce(Re);export{Fe as P,Ve as p};