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

function countBoolean(boolList) {
  return 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, {
    ...props,
    "format": format,
    "prefixCls": prefixCls
  }, null), createVNode(TimeBody, {
    ...props,
    "prefixCls": prefixCls,
    "activeColumnIndex": activeColumnIndex.value,
    "operationRef": bodyOperationRef
  }, null)]);
}
TimePanel.displayName = "TimePanel";
TimePanel.inheritAttrs = false;

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