import{ab as Y,aa as E,b2 as k,_ as S,c as T,bG as x,d as I,r as v,e as N,w as M,bD as D,a as _,h as j,ad as B,k as G}from"./index-f1aa8576.js";import{p as P,P as K}from"./index-2eae8c9e.js";const R=Y({},P,{modelValue:E(),filter:Function,formatter:{type:Function,default:(t,n)=>n}}),U=Object.keys(P);function Z(t,n){if(t<0)return[];const c=Array(t);let a=-1;for(;++a<t;)c[a]=n(a);return c}const $=(t,n)=>32-new Date(t,n-1,32).getDate(),f=(t,n,c,a,r,s)=>{const l=Z(n-t+1,m=>{const i=k(t+m);return a(c,{text:i,value:i})});return r?r(c,l,s):l},q=(t,n)=>t.map((c,a)=>{const r=n[a];if(r.length){const s=+r[0].value,l=+r[r.length-1].value;return k(S(+c,s,l))}return c}),V=new Date().getFullYear(),[z]=T("date-picker"),H=Y({},R,{columnsType:{type:Array,default:()=>["year","month","day"]},minDate:{type:Date,default:()=>new Date(V-10,0,1),validator:x},maxDate:{type:Date,default:()=>new Date(V+10,11,31),validator:x}});var J=I({name:z,props:H,emits:["confirm","cancel","change","update:modelValue"],setup(t,{emit:n,slots:c}){const a=v(t.modelValue),r=v(!1),s=()=>{const e=t.minDate.getFullYear(),o=t.maxDate.getFullYear();return f(e,o,"year",t.formatter,t.filter)},l=e=>e===t.minDate.getFullYear(),m=e=>e===t.maxDate.getFullYear(),i=e=>e===t.minDate.getMonth()+1,w=e=>e===t.maxDate.getMonth()+1,h=e=>{const{minDate:o,columnsType:u}=t,d=u.indexOf(e),y=r.value?t.modelValue[d]:a.value[d];if(y)return+y;switch(e){case"year":return o.getFullYear();case"month":return o.getMonth()+1;case"day":return o.getDate()}},F=()=>{const e=h("year"),o=l(e)?t.minDate.getMonth()+1:1,u=m(e)?t.maxDate.getMonth()+1:12;return f(o,u,"month",t.formatter,t.filter)},C=()=>{const e=h("year"),o=h("month"),u=l(e)&&i(o)?t.minDate.getDate():1,d=m(e)&&w(o)?t.maxDate.getDate():$(e,o);return f(u,d,"day",t.formatter,t.filter)},g=N(()=>t.columnsType.map(e=>{switch(e){case"year":return s();case"month":return F();case"day":return C();default:throw new Error(`[Vant] DatePicker: unsupported columns type: ${e}`)}}));M(a,e=>{D(e,t.modelValue)||n("update:modelValue",e)}),M(()=>t.modelValue,(e,o)=>{r.value=D(o,a.value),e=q(e,g.value),D(e,a.value)||(a.value=e),r.value=!1},{immediate:!0});const O=(...e)=>n("change",...e),b=(...e)=>n("cancel",...e),A=(...e)=>n("confirm",...e);return()=>_(K,j({modelValue:a.value,"onUpdate:modelValue":e=>a.value=e,columns:g.value,onChange:O,onCancel:b,onConfirm:A},B(t,U)),c)}});const W=G(J);export{W as D};
