import{defineComponent as $,ref as A,createVNode as f}from"vue";import{FormItemInputContext as x}from"../form/FormItemContext.mjs";import"../radio/index.mjs";import w from"../select/index.mjs";import P from"../radio/Group.mjs";import S from"../radio/RadioButton.mjs";const z=10,D=20;function I(c){const{fullscreen:u,validRange:o,generateConfig:e,locale:a,prefixCls:n,value:s,onChange:m,divRef:g}=c,h=e.getYear(s||e.getNow());let r=h-z,i=r+D;o&&(r=e.getYear(o[0]),i=e.getYear(o[1])+1);const C=a&&a.year==="年"?"年":"",p=[];for(let t=r;t<i;t++)p.push({label:`${t}${C}`,value:t});return f(w,{size:u?void 0:"small",options:p,value:h,class:`${n}-year-select`,onChange:t=>{let l=e.setYear(s,t);if(o){const[d,v]=o,M=e.getYear(l),Y=e.getMonth(l);M===e.getYear(v)&&Y>e.getMonth(v)&&(l=e.setMonth(l,e.getMonth(v))),M===e.getYear(d)&&Y<e.getMonth(d)&&(l=e.setMonth(l,e.getMonth(d)))}m(l)},getPopupContainer:()=>g.value},null)}I.inheritAttrs=!1;function y(c){const{prefixCls:u,fullscreen:o,validRange:e,value:a,generateConfig:n,locale:s,onChange:m,divRef:g}=c,h=n.getMonth(a||n.getNow());let r=0,i=11;if(e){const[t,l]=e,d=n.getYear(a);n.getYear(l)===d&&(i=n.getMonth(l)),n.getYear(t)===d&&(r=n.getMonth(t))}const C=s.shortMonths||n.locale.getShortMonths(s.locale),p=[];for(let t=r;t<=i;t+=1)p.push({label:C[t],value:t});return f(w,{size:o?void 0:"small",class:`${u}-month-select`,value:h,options:p,onChange:t=>{m(n.setMonth(a,t))},getPopupContainer:()=>g.value},null)}y.inheritAttrs=!1;function R(c){const{prefixCls:u,locale:o,mode:e,fullscreen:a,onModeChange:n}=c;return f(P,{onChange:({target:{value:s}})=>{n(s)},value:e,size:a?void 0:"small",class:`${u}-mode-switch`},{default:()=>[f(S,{value:"month"},{default:()=>[o.month]}),f(S,{value:"year"},{default:()=>[o.year]})]})}R.inheritAttrs=!1;const E=$({name:"CalendarHeader",inheritAttrs:!1,props:["mode","prefixCls","value","validRange","generateConfig","locale","mode","fullscreen"],setup(c,{attrs:u}){const o=A(null),e=x.useInject();return x.useProvide(e,{isFormItemInput:!1}),()=>{const a={...c,...u},{prefixCls:n,fullscreen:s,mode:m,onChange:g,onModeChange:h}=a,r={...a,fullscreen:s,divRef:o};return f("div",{class:`${n}-header`,ref:o},[f(I,{...r,onChange:i=>{g(i,"year")}},null),m==="month"&&f(y,{...r,onChange:i=>{g(i,"month")}},null),f(R,{...r,onModeChange:h},null)])}}});export{E as default};
