import e from"../_util/classNames.mjs";import t from"./locale/en_US.mjs";import{useLocaleReceiver as n}from"../locale/LocaleReceiver.mjs";import r from"../config-provider/hooks/useConfigInject.mjs";import i from"../_util/hooks/useMergedState.mjs";import a from"../vc-picker/PickerPanel.mjs";import o from"./Header.mjs";import s from"./style/index.mjs";import{computed as c,createVNode as l,defineComponent as u,toRef as d}from"vue";function f(f){function p(e,t){return e&&t&&f.getYear(e)===f.getYear(t)}function m(e,t){return p(e,t)&&f.getMonth(e)===f.getMonth(t)}function h(e,t){return m(e,t)&&f.getDate(e)===f.getDate(t)}let g=u({name:`ACalendar`,inheritAttrs:!1,props:{prefixCls:String,locale:{type:Object,default:void 0},validRange:{type:Array,default:void 0},disabledDate:{type:Function,default:void 0},dateFullCellRender:{type:Function,default:void 0},dateCellRender:{type:Function,default:void 0},monthFullCellRender:{type:Function,default:void 0},monthCellRender:{type:Function,default:void 0},headerRender:{type:Function,default:void 0},value:{type:[Object,String],default:void 0},defaultValue:{type:[Object,String],default:void 0},mode:{type:String,default:void 0},fullscreen:{type:Boolean,default:void 0},onChange:{type:Function,default:void 0},"onUpdate:value":{type:Function,default:void 0},onPanelChange:{type:Function,default:void 0},onSelect:{type:Function,default:void 0},valueFormat:{type:String,default:void 0}},slots:Object,setup(u,{emit:g,slots:_,attrs:v}){let y=u,{prefixCls:b,direction:x}=r(`picker`,y),[S,C]=s(b),w=c(()=>`${b.value}-calendar`),T=e=>y.valueFormat?f.toString(e,y.valueFormat):e,E=c(()=>y.value?y.valueFormat?f.toDate(y.value,y.valueFormat):y.value:y.value===``?void 0:y.value),[D,O]=i(()=>E.value||f.getNow(),{defaultValue:c(()=>y.defaultValue?y.valueFormat?f.toDate(y.defaultValue,y.valueFormat):y.defaultValue:y.defaultValue===``?void 0:y.defaultValue).value,value:E}),[k,A]=i(`month`,{value:d(y,`mode`)}),j=c(()=>k.value===`year`?`month`:`date`),M=c(()=>e=>(y.validRange?f.isAfter(y.validRange[0],e)||f.isAfter(e,y.validRange[1]):!1)||!!y.disabledDate?.(e)),N=(e,t)=>{g(`panelChange`,T(e),t)},P=e=>{if(O(e),!h(e,D.value)){(j.value===`date`&&!m(e,D.value)||j.value===`month`&&!p(e,D.value))&&N(e,k.value);let t=T(e);g(`update:value`,t),g(`change`,t)}},F=e=>{A(e),N(D.value,e)},I=(e,t)=>{P(e),g(`select`,T(e),{source:t})},[L]=n(`Calendar`,c(()=>{let{locale:e}=y,n={...t,...e};return n.lang={...n.lang,...(e||{}).lang},n}));return()=>{let t=f.getNow(),{dateFullCellRender:n=_?.dateFullCellRender,dateCellRender:r=_?.dateCellRender,monthFullCellRender:i=_?.monthFullCellRender,monthCellRender:s=_?.monthCellRender,headerRender:c=_?.headerRender,fullscreen:u=!0,validRange:d}=y,p=({current:i})=>n?n({current:i}):l(`div`,{class:e(`${b.value}-cell-inner`,`${w.value}-date`,{[`${w.value}-date-today`]:h(t,i)})},[l(`div`,{class:`${w.value}-date-value`},[String(f.getDate(i)).padStart(2,`0`)]),l(`div`,{class:`${w.value}-date-content`},[r&&r({current:i})])]),g=({current:n},r)=>{if(i)return i({current:n});let a=r.shortMonths||f.locale.getShortMonths(r.locale);return l(`div`,{class:e(`${b.value}-cell-inner`,`${w.value}-date`,{[`${w.value}-date-today`]:m(t,n)})},[l(`div`,{class:`${w.value}-date-value`},[a[f.getMonth(n)]]),l(`div`,{class:`${w.value}-date-content`},[s&&s({current:n})])])};return S(l(`div`,{...v,class:e(w.value,{[`${w.value}-full`]:u,[`${w.value}-mini`]:!u,[`${w.value}-rtl`]:x.value===`rtl`},v.class,C.value)},[c?c({value:D.value,type:k.value,onChange:e=>{I(e,`customize`)},onTypeChange:F}):l(o,{prefixCls:w.value,value:D.value,generateConfig:f,mode:k.value,fullscreen:u,locale:L.value.lang,validRange:d,onChange:I,onModeChange:F},null),l(a,{value:D.value,prefixCls:b.value,locale:L.value.lang,generateConfig:f,dateRender:p,monthCellRender:e=>g(e,L.value.lang),onSelect:e=>{I(e,j.value)},mode:j.value,picker:j.value,disabledDate:M.value,hideHeader:!0},null)]))}}});return g.install=function(e){return e.component(g.name,g),e},g}export{f as default};