'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../../utils/index.cjs');
var uiUtil = require('../../utils/uiUtil.cjs');
var useMergeProps = require('../../hooks/useMergeProps.cjs');
var TimeHeader = require('./TimeHeader.cjs');
var TimeBody = require('./TimeBody.cjs');
var _class = require('../../../../../utils/dom/class.cjs');

function countBoolean(boolList) {
  return boolList.filter((bool) => bool !== false).length;
}
function TimePanel(_props) {
  const props = useMergeProps.default(_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 = vue.ref();
  const activeColumnIndex = vue.ref(-1);
  const columnsCount = countBoolean([showHour, showMinute, showSecond, use12Hours]);
  operationRef.value = {
    onKeydown: (event) => uiUtil.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 vue.createVNode("div", {
    "class": _class.classNames(panelPrefixCls, {
      [`${panelPrefixCls}-active`]: active
    })
  }, [vue.createVNode(TimeHeader.default, {
    ...props,
    "format": format,
    "prefixCls": prefixCls
  }, null), vue.createVNode(TimeBody.default, {
    ...props,
    "prefixCls": prefixCls,
    "activeColumnIndex": activeColumnIndex.value,
    "operationRef": bodyOperationRef
  }, null)]);
}
TimePanel.displayName = "TimePanel";
TimePanel.inheritAttrs = false;

exports.default = TimePanel;
//# sourceMappingURL=index.cjs.map
