import{E as V,d as q,ax as z,b7 as de,W as M,j as c,bh as me,U as $,a2 as he,ak as ue,G as p,Y as ee,av as ge,aB as j,a0 as le,H as B,ab as ve,bb as ie,a3 as X,aa as ye,aS as De,au as Z,ah as be,a8 as we,T as se,B as ke,O as Te}from"./ResizeObserver.es.b7226882.js";import{u as Se}from"./use-refs.428b450a.js";import{g as xe}from"./utils.db47622f.js";import{u as Me}from"./index.969bba7f.js";const[Re,f,I]=V("calendar"),Oe=e=>I("monthTitle",e.getFullYear(),e.getMonth()+1);function te(e,s){const l=e.getFullYear(),d=s.getFullYear();if(l===d){const D=e.getMonth(),T=s.getMonth();return D===T?0:D>T?1:-1}return l>d?1:-1}function R(e,s){const l=te(e,s);if(l===0){const d=e.getDate(),D=s.getDate();return d===D?0:d>D?1:-1}return l}const U=e=>new Date(e),ce=e=>Array.isArray(e)?e.map(U):U(e);function oe(e,s){const l=U(e);return l.setDate(l.getDate()+s),l}const ne=e=>oe(e,-1),fe=e=>oe(e,1),ae=()=>{const e=new Date;return e.setHours(0,0,0,0),e};function Ce(e){const s=e[0].getTime();return(e[1].getTime()-s)/(1e3*60*60*24)+1}const[Pe]=V("calendar-day");var Be=q({name:Pe,props:{item:z(Object),color:String,index:Number,offset:de(0),rowHeight:String},emits:["click"],setup(e,{emit:s,slots:l}){const d=M(()=>{const{item:a,index:h,color:k,offset:A,rowHeight:C}=e,S={height:C};if(a.type==="placeholder")return S.width="100%",S;if(h===0&&(S.marginLeft=`${100*A/7}%`),k)switch(a.type){case"end":case"start":case"start-end":case"multiple-middle":case"multiple-selected":S.background=k;break;case"middle":S.color=k;break}return S}),D=()=>{e.item.type!=="disabled"&&s("click",e.item)},T=()=>{const{topInfo:a}=e.item;if(a||l["top-info"])return c("div",{class:f("top-info")},[l["top-info"]?l["top-info"](e.item):a])},O=()=>{const{bottomInfo:a}=e.item;if(a||l["bottom-info"])return c("div",{class:f("bottom-info")},[l["bottom-info"]?l["bottom-info"](e.item):a])},b=()=>{const{item:a,color:h,rowHeight:k}=e,{type:A,text:C}=a,S=[T(),C,O()];return A==="selected"?c("div",{class:f("selected-day"),style:{width:k,height:k,background:h}},[S]):S};return()=>{const{type:a,className:h}=e.item;return a==="placeholder"?c("div",{class:f("day"),style:d.value},null):c("div",{role:"gridcell",style:d.value,class:[f("day",a),h],tabindex:a==="disabled"?void 0:-1,onClick:D},[b()])}}});const[Ae]=V("calendar-month"),He={date:z(Date),type:String,color:String,minDate:z(Date),maxDate:z(Date),showMark:Boolean,rowHeight:p,formatter:Function,lazyRender:Boolean,currentDate:[Date,Array],allowSameDay:Boolean,showSubtitle:Boolean,showMonthTitle:Boolean,firstDayOfWeek:Number};var Ie=q({name:Ae,props:He,emits:["click","update-height"],setup(e,{emit:s,slots:l}){const[d,D]=me(),T=$(),O=$(),b=Me(O),a=M(()=>Oe(e.date)),h=M(()=>he(e.rowHeight)),k=M(()=>{const o=e.date.getDay();return e.firstDayOfWeek?(o+7-e.firstDayOfWeek)%7:o}),A=M(()=>xe(e.date.getFullYear(),e.date.getMonth()+1)),C=M(()=>d.value||!e.lazyRender),S=()=>a.value,W=o=>{const m=g=>e.currentDate.some(u=>R(u,g)===0);if(m(o)){const g=ne(o),u=fe(o),t=m(g),n=m(u);return t&&n?"multiple-middle":t?"end":n?"start":"multiple-selected"}return""},_=o=>{const[m,g]=e.currentDate;if(!m)return"";const u=R(o,m);if(!g)return u===0?"start":"";const t=R(o,g);return e.allowSameDay&&u===0&&t===0?"start-end":u===0?"start":t===0?"end":u>0&&t<0?"middle":""},N=o=>{const{type:m,minDate:g,maxDate:u,currentDate:t}=e;if(R(o,g)<0||R(o,u)>0)return"disabled";if(t===null)return"";if(Array.isArray(t)){if(m==="multiple")return W(o);if(m==="range")return _(o)}else if(m==="single")return R(o,t)===0?"selected":"";return""},Y=o=>{if(e.type==="range"){if(o==="start"||o==="end")return I(o);if(o==="start-end")return`${I("start")}/${I("end")}`}},E=()=>{if(e.showMonthTitle)return c("div",{class:f("month-title")},[a.value])},G=()=>{if(e.showMark&&C.value)return c("div",{class:f("month-mark")},[e.date.getMonth()+1])},F=M(()=>{const o=Math.ceil((A.value+k.value)/7);return Array(o).fill({type:"placeholder"})}),x=M(()=>{const o=[],m=e.date.getFullYear(),g=e.date.getMonth();for(let u=1;u<=A.value;u++){const t=new Date(m,g,u),n=N(t);let r={date:t,type:n,text:u,bottomInfo:Y(n)};e.formatter&&(r=e.formatter(r)),o.push(r)}return o}),L=M(()=>x.value.filter(o=>o.type==="disabled")),J=(o,m)=>{if(T.value){const g=ee(T.value),u=F.value.length,n=(Math.ceil((m.getDate()+k.value)/7)-1)*g.height/u;ge(o,g.top+n+o.scrollTop-ee(o).top)}},K=(o,m)=>c(Be,{item:o,index:m,color:e.color,offset:k.value,rowHeight:h.value,onClick:g=>s("click",g)},j(l,["top-info","bottom-info"])),Q=()=>c("div",{ref:T,role:"grid",class:f("days")},[G(),(C.value?x:F).value.map(K)]);return ue({getTitle:S,getHeight:()=>b.value,setVisible:D,scrollToDate:J,disabledDays:L}),()=>c("div",{class:f("month"),ref:O},[E(),Q()])}});const[We]=V("calendar-header");var Ne=q({name:We,props:{title:String,subtitle:String,showTitle:Boolean,showSubtitle:Boolean,firstDayOfWeek:Number},emits:["click-subtitle"],setup(e,{slots:s,emit:l}){const d=()=>{if(e.showTitle){const b=e.title||I("title"),a=s.title?s.title():b;return c("div",{class:f("header-title")},[a])}},D=b=>l("click-subtitle",b),T=()=>{if(e.showSubtitle){const b=s.subtitle?s.subtitle():e.subtitle;return c("div",{class:f("header-subtitle"),onClick:D},[b])}},O=()=>{const{firstDayOfWeek:b}=e,a=I("weekdays"),h=[...a.slice(b,7),...a.slice(0,b)];return c("div",{class:f("weekdays")},[h.map(k=>c("span",{class:f("weekday")},[k]))])};return()=>c("div",{class:f("header")},[d(),T(),O()])}});const Fe={show:Boolean,type:le("single"),title:String,color:String,round:B,readonly:Boolean,poppable:B,maxRange:ve(null),position:le("bottom"),teleport:[String,Object],showMark:B,showTitle:B,formatter:Function,rowHeight:p,confirmText:String,rangePrompt:String,lazyRender:B,showConfirm:B,defaultDate:[Date,Array],allowSameDay:Boolean,showSubtitle:B,closeOnPopstate:B,showRangePrompt:B,confirmDisabledText:String,closeOnClickOverlay:B,safeAreaInsetTop:Boolean,safeAreaInsetBottom:B,minDate:{type:Date,validator:ie,default:ae},maxDate:{type:Date,validator:ie,default:()=>{const e=ae();return new Date(e.getFullYear(),e.getMonth()+6,e.getDate())}},firstDayOfWeek:{type:p,default:0,validator:e=>e>=0&&e<=6}};var $e=q({name:Re,props:Fe,emits:["select","confirm","unselect","month-show","over-range","update:show","click-subtitle"],setup(e,{emit:s,slots:l}){const d=(t,n=e.minDate,r=e.maxDate)=>R(t,n)===-1?n:R(t,r)===1?r:t,D=(t=e.defaultDate)=>{const{type:n,minDate:r,maxDate:i}=e;if(t===null)return t;const v=ae();if(n==="range"){Array.isArray(t)||(t=[]);const w=d(t[0]||v,r,ne(i)),H=d(t[1]||v,fe(r));return[w,H]}return n==="multiple"?Array.isArray(t)?t.map(w=>d(w)):[d(v)]:((!t||Array.isArray(t))&&(t=v),d(t))};let T;const O=$(),b=$(""),a=$(D()),[h,k]=Se(),A=M(()=>e.firstDayOfWeek?+e.firstDayOfWeek%7:0),C=M(()=>{const t=[],n=new Date(e.minDate);n.setDate(1);do t.push(new Date(n)),n.setMonth(n.getMonth()+1);while(te(n,e.maxDate)!==1);return t}),S=M(()=>{if(a.value){if(e.type==="range")return!a.value[0]||!a.value[1];if(e.type==="multiple")return!a.value.length}return!a.value}),W=()=>{const t=be(O.value),n=t+T,r=C.value.map((y,P)=>h.value[P].getHeight()),i=r.reduce((y,P)=>y+P,0);if(n>i&&t>0)return;let v=0,w;const H=[-1,-1];for(let y=0;y=t&&(H[1]=y,w||(w=P,H[0]=y),h.value[y].showed||(h.value[y].showed=!0,s("month-show",{date:P.date,title:P.getTitle()}))),v+=r[y]}C.value.forEach((y,P)=>{const re=P>=H[0]-1&&P<=H[1]+1;h.value[P].setVisible(re)}),w&&(b.value=w.getTitle())},_=t=>{Z(()=>{C.value.some((n,r)=>te(n,t)===0?(O.value&&h.value[r].scrollToDate(O.value,t),!0):!1),W()})},N=()=>{if(!(e.poppable&&!e.show))if(a.value){const t=e.type==="single"?a.value:a.value[0];_(t)}else Z(W)},Y=()=>{e.poppable&&!e.show||Z(()=>{T=Math.floor(ee(O).height),N()})},E=(t=D())=>{a.value=t,N()},G=t=>{const{maxRange:n,rangePrompt:r,showRangePrompt:i}=e;return n&&Ce(t)>n?(i&&se(r||I("rangePrompt",n)),s("over-range"),!1):!0},F=()=>{var t;return s("confirm",(t=a.value)!=null?t:ce(a.value))},x=(t,n)=>{const r=i=>{a.value=i,s("select",ce(i))};if(n&&e.type==="range"&&!G(t)){r([t[0],oe(t[0],+e.maxRange-1)]);return}r(t),n&&!e.showConfirm&&F()},L=(t,n,r)=>{var i;return(i=t.find(v=>R(n,v.date)===-1&&R(v.date,r)===-1))==null?void 0:i.date},J=M(()=>h.value.reduce((t,n)=>{var r,i;return t.push(...(i=(r=n.disabledDays)==null?void 0:r.value)!=null?i:[]),t},[])),K=t=>{if(e.readonly||!t.date)return;const{date:n}=t,{type:r}=e;if(r==="range"){if(!a.value){x([n]);return}const[i,v]=a.value;if(i&&!v){const w=R(n,i);if(w===1){const H=L(J.value,i,n);if(H){const y=ne(H);R(i,y)===-1?x([i,y]):x([n])}else x([i,n],!0)}else w===-1?x([n]):e.allowSameDay&&x([n,n],!0)}else x([n])}else if(r==="multiple"){if(!a.value){x([n]);return}const i=a.value,v=i.findIndex(w=>R(w,n)===0);if(v!==-1){const[w]=i.splice(v,1);s("unselect",U(w))}else e.maxRange&&i.length>=e.maxRange?se(e.rangePrompt||I("rangePrompt",e.maxRange)):x([...i,n])}else x(n,!0)},Q=t=>s("update:show",t),o=(t,n)=>{const r=n!==0||!e.showSubtitle;return c(Ie,we({ref:k(n),date:t,currentDate:a.value,showMonthTitle:r,firstDayOfWeek:A.value},j(e,["type","color","minDate","maxDate","showMark","formatter","rowHeight","lazyRender","showSubtitle","allowSameDay"]),{onClick:K}),j(l,["top-info","bottom-info"]))},m=()=>{if(l.footer)return l.footer();if(e.showConfirm){const t=l["confirm-text"],n=S.value,r=n?e.confirmDisabledText:e.confirmText;return c(ke,{round:!0,block:!0,type:"danger",color:e.color,class:f("confirm"),disabled:n,nativeType:"button",onClick:F},{default:()=>[t?t({disabled:n}):r||I("confirm")]})}},g=()=>c("div",{class:[f("footer"),{"van-safe-area-bottom":e.safeAreaInsetBottom}]},[m()]),u=()=>c("div",{class:f()},[c(Ne,{title:e.title,subtitle:b.value,showTitle:e.showTitle,showSubtitle:e.showSubtitle,firstDayOfWeek:A.value,"onClick-subtitle":t=>s("click-subtitle",t)},j(l,["title","subtitle"])),c("div",{ref:O,class:f("body"),onScroll:W},[C.value.map(o)]),g()]);return X(()=>e.show,Y),X(()=>[e.type,e.minDate,e.maxDate],()=>E(D(a.value))),X(()=>e.defaultDate,(t=null)=>{a.value=t,N()}),ue({reset:E,scrollToDate:_}),ye(Y),()=>e.poppable?c(De,{show:e.show,class:f("popup"),round:e.round,position:e.position,closeable:e.showTitle||e.showSubtitle,teleport:e.teleport,closeOnPopstate:e.closeOnPopstate,safeAreaInsetTop:e.safeAreaInsetTop,closeOnClickOverlay:e.closeOnClickOverlay,"onUpdate:show":Q},{default:u}):u()}});const je=Te($e);export{je as C};