import{cloneElement as e}from"../../../_util/vnode.mjs";import{setTime as t}from"../../utils/timeUtil.mjs";import{leftPad as n}from"../../utils/miscUtil.mjs";import r from"./TimeUnitColumn.mjs";import{computed as i,createVNode as a,defineComponent as o,onBeforeUpdate as s,ref as c,watchEffect as l}from"vue";function u(e,t,r,i){let a=[];for(let o=e;o<=t;o+=r)a.push({label:n(o,2),value:o,disabled:(i||[]).includes(o)});return a}var d=o({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(o){let d=i(()=>o.value?o.generateConfig.getHour(o.value):-1),f=i(()=>o.use12Hours?d.value>=12:!1),p=i(()=>o.use12Hours?d.value%12:d.value),m=i(()=>o.value?o.generateConfig.getMinute(o.value):-1),h=i(()=>o.value?o.generateConfig.getSecond(o.value):-1),g=c(o.generateConfig.getNow()),_=c(),v=c(),y=c();s(()=>{g.value=o.generateConfig.getNow()}),l(()=>{if(o.disabledTime){let e=o.disabledTime(g);[_.value,v.value,y.value]=[e.disabledHours,e.disabledMinutes,e.disabledSeconds]}else[_.value,v.value,y.value]=[o.disabledHours,o.disabledMinutes,o.disabledSeconds]});let b=(e,n,r,i)=>{let a=o.value||o.generateConfig.getNow(),s=Math.max(0,n),c=Math.max(0,r),l=Math.max(0,i);return a=t(o.generateConfig,a,!o.use12Hours||!e?s:s+12,c,l),a},x=i(()=>u(0,23,o.hourStep??1,_.value&&_.value())),S=i(()=>{if(!o.use12Hours)return[!1,!1];let e=[!0,!0];return x.value.forEach(({disabled:t,value:n})=>{t||(n>=12?e[1]=!1:e[0]=!1)}),e}),C=i(()=>o.use12Hours?x.value.filter(f.value?e=>e.value>=12:e=>e.value<12).map(e=>{let t=e.value%12,r=t===0?`12`:n(t,2);return{...e,label:r,value:t}}):x.value),w=i(()=>u(0,59,o.minuteStep??1,v.value&&v.value(d.value))),T=i(()=>u(0,59,o.secondStep??1,y.value&&y.value(d.value,m.value)));return()=>{let{prefixCls:t,operationRef:n,activeColumnIndex:i,showHour:s,showMinute:c,showSecond:l,use12Hours:u,hideDisabledOptions:d,onSelect:g}=o,_=[],v=`${t}-content`,y=`${t}-time-panel`;n.value={onUpDown:e=>{let t=_[i];if(t){let n=t.units.findIndex(e=>e.value===t.value),r=t.units.length;for(let i=1;i<r;i+=1){let a=t.units[(n+e*i+r)%r];if(a.disabled!==!0){t.onSelect(a.value);break}}}}};function x(t,n,r,a,o){t!==!1&&_.push({node:e(n,{prefixCls:y,value:r,active:i===_.length,onSelect:o,units:a,hideDisabledOptions:d}),onSelect:o,value:r,units:a})}x(s,a(r,{key:`hour`},null),p.value,C.value,e=>{g(b(f.value,e,m.value,h.value),`mouse`)}),x(c,a(r,{key:`minute`},null),m.value,w.value,e=>{g(b(f.value,p.value,e,h.value),`mouse`)}),x(l,a(r,{key:`second`},null),h.value,T.value,e=>{g(b(f.value,p.value,m.value,e),`mouse`)});let E=-1;return typeof f.value==`boolean`&&(E=+!!f.value),x(u===!0,a(r,{key:`12hours`},null),E,[{label:`AM`,value:0,disabled:S.value[0]},{label:`PM`,value:1,disabled:S.value[1]}],e=>{g(b(!!e,p.value,m.value,h.value),`mouse`)}),a(`div`,{class:v},[_.map(({node:e})=>e)])}}});export{d as default};