import { ref, createVNode, mergeProps } from 'vue';
import { createKeydownHandler } from '../../utils/uiUtil.mjs';
import useMergeProps from '../../hooks/useMergeProps.mjs';
import classNames from '../../../_util/classNames.mjs';
import TimeHeader from './TimeHeader.mjs';
import TimeBody from './TimeBody.mjs';

const countBoolean = (boolList) => boolList.filter((bool) => bool !== false).length;
function TimePanel(_props) {
  const props = useMergeProps(_props);
  const {
    generateConfig,
    format = "HH:mm:ss",
    prefixCls,
    active,
    operationRef,
    showHour,
    showMinute,
    showSecond,
    use12Hours = false,
    onSelect,
    value
  } = props;
  const panelPrefixCls = `${prefixCls}-time-panel`;
  const bodyOperationRef = ref();
  const activeColumnIndex = ref(-1);
  const columnsCount = countBoolean([showHour, showMinute, showSecond, use12Hours]);
  operationRef.value = {
    onKeydown: (event) => createKeydownHandler(event, {
      onLeftRight: (diff) => {
        activeColumnIndex.value = (activeColumnIndex.value + diff + columnsCount) % columnsCount;
      },
      onUpDown: (diff) => {
        if (activeColumnIndex.value === -1)
          activeColumnIndex.value = 0;
        else if (bodyOperationRef.value)
          bodyOperationRef.value.onUpDown(diff);
      },
      onEnter: () => {
        onSelect(value || generateConfig.getNow(), "key");
        activeColumnIndex.value = -1;
      }
    }),
    onBlur: () => {
      activeColumnIndex.value = -1;
    }
  };
  return createVNode("div", {
    "class": classNames(panelPrefixCls, {
      [`${panelPrefixCls}-active`]: active
    })
  }, [createVNode(TimeHeader, mergeProps(props, {
    "format": format,
    "prefixCls": prefixCls
  }), null), createVNode(TimeBody, mergeProps(props, {
    "prefixCls": prefixCls,
    "activeColumnIndex": activeColumnIndex.value,
    "operationRef": bodyOperationRef
  }), null)]);
}
TimePanel.displayName = "TimePanel";
TimePanel.inheritAttrs = false;

export { TimePanel as default };
//# sourceMappingURL=index.mjs.map
