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