'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var propType = require('../../../utils/vue/propType.cjs');
var is = require('../../../utils/is.cjs');
var _class = require('../../../utils/dom/class.cjs');

const STEP_INTERVAL = 200;
const STEP_DELAY = 600;
var StepHandler = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "StepHandler",
  inheritAttrs: false,
  props: {
    prefixCls: String,
    upDisabled: Boolean,
    downDisabled: Boolean,
    onStep: propType.functionType()
  },
  slots: Object,
  setup(props, {
    slots,
    emit
  }) {
    const stepTimeoutRef = vue.ref();
    const onStepMouseDown = (e, up) => {
      e.preventDefault();
      emit("step", up);
      function loopStep() {
        emit("step", up);
        stepTimeoutRef.value = setTimeout(loopStep, STEP_INTERVAL);
      }
      stepTimeoutRef.value = setTimeout(loopStep, STEP_DELAY);
    };
    const onStopStep = () => {
      clearTimeout(stepTimeoutRef.value);
    };
    vue.onBeforeUnmount(() => {
      onStopStep();
    });
    return () => {
      if (is.isMobile())
        return null;
      const {
        prefixCls,
        upDisabled,
        downDisabled
      } = props;
      const handlerClassName = `${prefixCls}-handler`;
      const upClassName = _class.classNames(handlerClassName, `${handlerClassName}-up`, {
        [`${handlerClassName}-up-disabled`]: upDisabled
      });
      const downClassName = _class.classNames(handlerClassName, `${handlerClassName}-down`, {
        [`${handlerClassName}-down-disabled`]: downDisabled
      });
      const sharedHandlerProps = {
        unselectable: "on",
        role: "button",
        onMouseup: onStopStep,
        onMouseleave: onStopStep
      };
      const {
        upNode,
        downNode
      } = slots;
      return vue.createVNode("div", {
        "class": `${handlerClassName}-wrap`
      }, [vue.createVNode("span", {
        ...sharedHandlerProps,
        "onMousedown": (e) => {
          onStepMouseDown(e, true);
        },
        "aria-label": "Increase Value",
        "aria-disabled": upDisabled,
        "class": upClassName
      }, [(upNode == null ? void 0 : upNode()) || vue.createVNode("span", {
        "unselectable": "on",
        "class": `${prefixCls}-handler-up-inner`
      }, null)]), vue.createVNode("span", {
        ...sharedHandlerProps,
        "onMousedown": (e) => {
          onStepMouseDown(e, false);
        },
        "aria-label": "Decrease Value",
        "aria-disabled": downDisabled,
        "class": downClassName
      }, [(downNode == null ? void 0 : downNode()) || vue.createVNode("span", {
        "unselectable": "on",
        "class": `${prefixCls}-handler-down-inner`
      }, null)])]);
    };
  }
});

exports.default = StepHandler;
//# sourceMappingURL=StepHandler.cjs.map
