import{defineComponent as z,computed as t,ref as P,onBeforeUpdate as F,watchEffect as G,createVNode as g}from"vue";import{cloneElement as J}from"../../../_util/vnode.mjs";import{leftPad as $}from"../../utils/miscUtil.mjs";import{setTime as K}from"../../utils/timeUtil.mjs";import T from"./TimeUnitColumn.mjs";function U(e,v,o,c){const s=[];for(let l=e;l<=v;l+=o)s.push({label:$(l,2),value:l,disabled:(c||[]).includes(l)});return s}const _=z({compatConfig:{MODE:3},name:"TimeBody",inheritAttrs:!1,props:["generateConfig","prefixCls","operationRef","activeColumnIndex","value","showHour","showMinute","showSecond","use12Hours","hourStep","minuteStep","secondStep","disabledHours","disabledMinutes","disabledSeconds","disabledTime","hideDisabledOptions","onSelect"],setup(e){const v=t(()=>e.value?e.generateConfig.getHour(e.value):-1),o=t(()=>e.use12Hours?v.value>=12:!1),c=t(()=>e.use12Hours?v.value%12:v.value),s=t(()=>e.value?e.generateConfig.getMinute(e.value):-1),l=t(()=>e.value?e.generateConfig.getSecond(e.value):-1),A=P(e.generateConfig.getNow()),b=P(),h=P(),C=P();F(()=>{A.value=e.generateConfig.getNow()}),G(()=>{if(e.disabledTime){const u=e.disabledTime(A);[b.value,h.value,C.value]=[u.disabledHours,u.disabledMinutes,u.disabledSeconds]}else[b.value,h.value,C.value]=[e.disabledHours,e.disabledMinutes,e.disabledSeconds]});const M=(u,a,i,k)=>{let m=e.value||e.generateConfig.getNow();const S=Math.max(0,a),I=Math.max(0,i),N=Math.max(0,k);return m=K(e.generateConfig,m,!e.use12Hours||!u?S:S+12,I,N),m},y=t(()=>U(0,23,e.hourStep??1,b.value&&b.value())),E=t(()=>{if(!e.use12Hours)return[!1,!1];const u=[!0,!0];return y.value.forEach(({disabled:a,value:i})=>{a||(i>=12?u[1]=!1:u[0]=!1)}),u}),L=t(()=>e.use12Hours?y.value.filter(o.value?u=>u.value>=12:u=>u.value<12).map(u=>{const a=u.value%12,i=a===0?"12":$(a,2);return{...u,label:i,value:a}}):y.value),R=t(()=>U(0,59,e.minuteStep??1,h.value&&h.value(v.value))),V=t(()=>U(0,59,e.secondStep??1,C.value&&C.value(v.value,s.value)));return()=>{const{prefixCls:u,operationRef:a,activeColumnIndex:i,showHour:k,showMinute:m,showSecond:S,use12Hours:I,hideDisabledOptions:N,onSelect:H}=e,x=[],j=`${u}-content`,q=`${u}-time-panel`;a.value={onUpDown:n=>{const d=x[i];if(d){const D=d.units.findIndex(r=>r.value===d.value),f=d.units.length;for(let r=1;r<f;r+=1){const O=d.units[(D+n*r+f)%f];if(O.disabled!==!0){d.onSelect(O.value);break}}}}};function w(n,d,D,f,r){n!==!1&&x.push({node:J(d,{prefixCls:q,value:D,active:i===x.length,onSelect:r,units:f,hideDisabledOptions:N}),onSelect:r,value:D,units:f})}w(k,g(T,{key:"hour"},null),c.value,L.value,n=>{H(M(o.value,n,s.value,l.value),"mouse")}),w(m,g(T,{key:"minute"},null),s.value,R.value,n=>{H(M(o.value,c.value,n,l.value),"mouse")}),w(S,g(T,{key:"second"},null),l.value,V.value,n=>{H(M(o.value,c.value,s.value,n),"mouse")});let B=-1;return typeof o.value=="boolean"&&(B=o.value?1:0),w(I===!0,g(T,{key:"12hours"},null),B,[{label:"AM",value:0,disabled:E.value[0]},{label:"PM",value:1,disabled:E.value[1]}],n=>{H(M(!!n,c.value,s.value,l.value),"mouse")}),g("div",{class:j},[x.map(({node:n})=>n)])}}});export{_ as default};
