import{c as O,ai as E,bi as f,d as T,r as g,e as b,w as y,bF as m,a as I,h as N,ak as S,k as A}from"./index-7945cc5d.js";import{s as B,f as K,a as u,g as R,p as U}from"./utils-ee38b6df.js";import{P as _}from"./index-d5e0922b.js";const x=new Date().getFullYear(),[$]=O("date-picker"),j=E({},B,{columnsType:{type:Array,default:()=>["year","month","day"]},minDate:{type:Date,default:()=>new Date(x-10,0,1),validator:f},maxDate:{type:Date,default:()=>new Date(x+10,11,31),validator:f}});var q=T({name:$,props:j,emits:["confirm","cancel","change","update:modelValue"],setup(a,{emit:r,slots:v}){const n=g(a.modelValue),l=g(!1),M=()=>{const e=a.minDate.getFullYear(),t=a.maxDate.getFullYear();return u(e,t,"year",a.formatter,a.filter)},i=e=>e===a.minDate.getFullYear(),d=e=>e===a.maxDate.getFullYear(),Y=e=>e===a.minDate.getMonth()+1,V=e=>e===a.maxDate.getMonth()+1,s=e=>{const{minDate:t,columnsType:o}=a,c=o.indexOf(e),D=l.value?a.modelValue[c]:n.value[c];if(D)return+D;switch(e){case"year":return t.getFullYear();case"month":return t.getMonth()+1;case"day":return t.getDate()}},k=()=>{const e=s("year"),t=i(e)?a.minDate.getMonth()+1:1,o=d(e)?a.maxDate.getMonth()+1:12;return u(t,o,"month",a.formatter,a.filter)},P=()=>{const e=s("year"),t=s("month"),o=i(e)&&Y(t)?a.minDate.getDate():1,c=d(e)&&V(t)?a.maxDate.getDate():R(e,t);return u(o,c,"day",a.formatter,a.filter)},h=b(()=>a.columnsType.map(e=>{switch(e){case"year":return M();case"month":return k();case"day":return P();default:throw new Error(`[Vant] DatePicker: unsupported columns type: ${e}`)}}));y(n,e=>{m(e,a.modelValue)||r("update:modelValue",e)}),y(()=>a.modelValue,(e,t)=>{l.value=m(t,n.value),e=K(e,h.value),m(e,n.value)||(n.value=e),l.value=!1},{immediate:!0});const C=(...e)=>r("change",...e),F=(...e)=>r("cancel",...e),w=(...e)=>r("confirm",...e);return()=>I(_,N({modelValue:n.value,"onUpdate:modelValue":e=>n.value=e,columns:h.value,onChange:C,onCancel:F,onConfirm:w},S(a,U)),v)}});const J=A(q);export{J as D};
