function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useState, useCallback, useEffect, useRef } from 'react';

/**
 * 管理步骤条状态的 Hook（支持受控和非受控模式）
 * 
 * @param current - 受控模式下的当前步骤
 * @param defaultCurrent - 非受控模式下的默认当前步骤
 * @param onChange - 步骤变更回调函数
 * @returns [currentStep, setCurrentStep] - 当前步骤和设置步骤的函数
 */
export function useStepsState(current) {
  var defaultCurrent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  var onChange = arguments.length > 2 ? arguments[2] : undefined;
  // 确保 defaultCurrent 是有效的数字
  var safeDefaultCurrent = typeof defaultCurrent === 'number' && !isNaN(defaultCurrent) && defaultCurrent >= 0 ? defaultCurrent : 0;

  // 确保 current 是有效的数字（如果提供）
  var safeCurrent = current !== undefined && typeof current === 'number' && !isNaN(current) && current >= 0 ? current : undefined;

  // 内部状态（非受控模式使用）
  var _useState = useState(safeDefaultCurrent),
    _useState2 = _slicedToArray(_useState, 2),
    innerCurrent = _useState2[0],
    setInnerCurrent = _useState2[1];

  // 记录上一次的步骤，用于判断变更方向
  var previousCurrentRef = useRef(safeDefaultCurrent);

  // 判断是否为受控模式
  var isControlled = safeCurrent !== undefined;

  // 当前步骤值
  var currentStep = isControlled ? safeCurrent : innerCurrent;

  // 设置步骤的函数
  var setCurrentStep = useCallback(function (value) {
    var previousCurrent = previousCurrentRef.current;

    // 非受控模式下更新内部状态
    if (!isControlled) {
      setInnerCurrent(value);
    }

    // 触发 onChange 回调
    if (onChange && value !== previousCurrent) {
      onChange(value);
    }

    // 更新上一次步骤记录
    previousCurrentRef.current = value;
  }, [isControlled, onChange]);

  // 受控模式下，同步更新 previousCurrentRef
  useEffect(function () {
    if (isControlled && safeCurrent !== undefined) {
      previousCurrentRef.current = safeCurrent;
    }
  }, [safeCurrent, isControlled]);
  return [currentStep, setCurrentStep];
}