import{defineComponent as J,computed as i,toRef as K,createVNode as o}from"vue";import C from"../_util/classNames.mjs";import N from"../_util/hooks/useMergedState.mjs";import Q from"../config-provider/hooks/useConfigInject.mjs";import{useLocaleReceiver as W}from"../locale/LocaleReceiver.mjs";import X from"../vc-picker/PickerPanel.mjs";import"../vc-trigger/Trigger.mjs";import"../_util/vue-types/index.mjs";import"../_util/raf.mjs";import"../vc-picker/panels/DecadePanel/index.mjs";import Z from"./Header.mjs";import _ from"../date-picker/locale/en_US.mjs";import ee from"./style/index.mjs";function me(n){function S(u,r){return u&&r&&n.getYear(u)===n.getYear(r)}function h(u,r){return S(u,r)&&n.getMonth(u)===n.getMonth(r)}function $(u,r){return h(u,r)&&n.getDate(u)===n.getDate(r)}const m=J({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:r,slots:s,attrs:M}){const l=u,{prefixCls:v,direction:O}=Q("picker",l),[k,L]=ee(v),d=i(()=>`${v.value}-calendar`),R=e=>l.valueFormat?n.toString(e,l.valueFormat):e,D=i(()=>l.value?l.valueFormat?n.toDate(l.value,l.valueFormat):l.value:l.value===""?void 0:l.value),Y=i(()=>l.defaultValue?l.valueFormat?n.toDate(l.defaultValue,l.valueFormat):l.defaultValue:l.defaultValue===""?void 0:l.defaultValue),[c,w]=N(()=>D.value||n.getNow(),{defaultValue:Y.value,value:D}),[p,H]=N("month",{value:K(l,"mode")}),f=i(()=>p.value==="year"?"month":"date"),T=i(()=>e=>(l.validRange?n.isAfter(l.validRange[0],e)||n.isAfter(e,l.validRange[1]):!1)||!!l.disabledDate?.(e)),V=(e,a)=>{r("panelChange",R(e),a)},z=e=>{if(w(e),!$(e,c.value)){(f.value==="date"&&!h(e,c.value)||f.value==="month"&&!S(e,c.value))&&V(e,p.value);const a=R(e);r("update:value",a),r("change",a)}},b=e=>{H(e),V(c.value,e)},g=(e,a)=>{z(e),r("select",R(e),{source:a})},B=i(()=>{const{locale:e}=l,a={..._,...e};return a.lang={...a.lang,...(e||{}).lang},a}),[y]=W("Calendar",B);return()=>{const e=n.getNow(),{dateFullCellRender:a=s?.dateFullCellRender,dateCellRender:x=s?.dateCellRender,monthFullCellRender:j=s?.monthFullCellRender,monthCellRender:A=s?.monthCellRender,headerRender:I=s?.headerRender,fullscreen:F=!0,validRange:U}=l,q=({current:t})=>a?a({current:t}):o("div",{class:C(`${v.value}-cell-inner`,`${d.value}-date`,{[`${d.value}-date-today`]:$(e,t)})},[o("div",{class:`${d.value}-date-value`},[String(n.getDate(t)).padStart(2,"0")]),o("div",{class:`${d.value}-date-content`},[x&&x({current:t})])]),E=({current:t},P)=>{if(j)return j({current:t});const G=P.shortMonths||n.locale.getShortMonths(P.locale);return o("div",{class:C(`${v.value}-cell-inner`,`${d.value}-date`,{[`${d.value}-date-today`]:h(e,t)})},[o("div",{class:`${d.value}-date-value`},[G[n.getMonth(t)]]),o("div",{class:`${d.value}-date-content`},[A&&A({current:t})])])};return k(o("div",{...M,class:C(d.value,{[`${d.value}-full`]:F,[`${d.value}-mini`]:!F,[`${d.value}-rtl`]:O.value==="rtl"},M.class,L.value)},[I?I({value:c.value,type:p.value,onChange:t=>{g(t,"customize")},onTypeChange:b}):o(Z,{prefixCls:d.value,value:c.value,generateConfig:n,mode:p.value,fullscreen:F,locale:y.value.lang,validRange:U,onChange:g,onModeChange:b},null),o(X,{value:c.value,prefixCls:v.value,locale:y.value.lang,generateConfig:n,dateRender:q,monthCellRender:t=>E(t,y.value.lang),onSelect:t=>{g(t,f.value)},mode:f.value,picker:f.value,disabledDate:T.value,hideHeader:!0},null)]))}}});return m.install=function(u){return u.component(m.name,m),u},m}export{me as default};
