import{ref as d,createVNode as m}from"vue";import i from"../../../_util/KeyCode.mjs";import N from"../../../_util/classNames.mjs";import R from"../../hooks/useMergeProps.mjs";import{tuple as S}from"../../utils/miscUtil.mjs";import{setDateTime as b}from"../../utils/timeUtil.mjs";import K from"../DatePanel/index.mjs";import M from"../TimePanel/index.mjs";const x=S("date","time");function D(V){const c=R(V),{prefixCls:y,operationRef:A,generateConfig:a,value:u,defaultValue:r,disabledTime:p,showTime:s,onSelect:v}=c,P=`${y}-datetime-panel`,n=d(null),g=d({}),f=d({}),o=typeof s=="object"?{...s}:{};function w(e){const l=x.indexOf(n.value)+e;return x[l]||null}const T=e=>{f.value.onBlur&&f.value.onBlur(e),n.value=null};A.value={onKeydown:e=>{if(e.which===i.TAB){const l=w(e.shiftKey?-1:1);return n.value=l,l&&e.preventDefault(),!0}if(n.value){const l=n.value==="date"?g:f;return l.value&&l.value.onKeydown&&l.value.onKeydown(e),!0}return[i.LEFT,i.RIGHT,i.UP,i.DOWN].includes(e.which)?(n.value="date",!0):!1},onBlur:T,onClose:T};const h=(e,l)=>{let t=e;l==="date"&&!u&&o.defaultValue?(t=a.setHour(t,a.getHour(o.defaultValue)),t=a.setMinute(t,a.getMinute(o.defaultValue)),t=a.setSecond(t,a.getSecond(o.defaultValue))):l==="time"&&!u&&r&&(t=a.setYear(t,a.getYear(r)),t=a.setMonth(t,a.getMonth(r)),t=a.setDate(t,a.getDate(r))),v&&v(t,"mouse")},C=p?p(u||null):{};return m("div",{class:N(P,{[`${P}-active`]:n.value})},[m(K,{...c,operationRef:g,active:n.value==="date",onSelect:e=>{h(b(a,e,!u&&typeof s=="object"?s.defaultValue:null),"date")}},null),m(M,{...c,format:void 0,...o,...C,disabledTime:null,defaultValue:void 0,operationRef:f,active:n.value==="time",onSelect:e=>{h(e,"time")}},null)])}D.displayName="DatetimePanel";D.inheritAttrs=!1;export{D as default};
