var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_ConfigProviderContext = __toESM(require("../config-provider/ConfigProviderContext"));
var import_RollingTextItem = __toESM(require("./RollingTextItem"));
var import_utils = require("../utils");
var import_raf = require("../utils/raf");
const CIRCLE_NUM = 2;
const RollingText = /* @__PURE__ */ (0, import_react.forwardRef)((_a, ref) => {
  var _b = _a, {
    duration,
    direction,
    height,
    textList,
    startNum,
    targetNum,
    autoStart
  } = _b, props = __objRest(_b, [
    "duration",
    "direction",
    "height",
    "textList",
    "startNum",
    "targetNum",
    "autoStart"
  ]);
  const {
    prefixCls,
    createNamespace
  } = (0, import_react.useContext)(import_ConfigProviderContext.default);
  const [bem] = createNamespace("rolling-text", prefixCls);
  const [rolling, setRolling] = (0, import_react.useState)(autoStart);
  const isCustomType = (0, import_react.useMemo)(() => Array.isArray(textList) && textList.length, [textList]);
  const itemLength = (0, import_react.useMemo)(() => {
    if (isCustomType)
      return textList[0].length;
    return `${Math.max(startNum, targetNum)}`.length;
  }, [startNum, targetNum]);
  const getTextArrByIdx = (idx) => {
    const result = [];
    for (let i = 0; i < textList.length; i++) {
      result.push(textList[i][idx]);
    }
    return result;
  };
  const targetNumArr = (0, import_react.useMemo)(() => {
    if (isCustomType)
      return new Array(itemLength).fill("");
    return (0, import_utils.padZero)(targetNum, itemLength).split("");
  }, [isCustomType, itemLength, targetNum]);
  const startNumArr = (0, import_react.useMemo)(() => (0, import_utils.padZero)(startNum, itemLength).split(""), [startNum, itemLength]);
  const getFigureArr = (i) => {
    const start2 = +startNumArr[i];
    const target = +targetNumArr[i];
    const result = [];
    for (let index = start2; index <= 9; index++) {
      result.push(index);
    }
    for (let index2 = 0; index2 <= CIRCLE_NUM; index2++) {
      for (let j = 0; j <= 9; j++) {
        result.push(j);
      }
    }
    for (let index3 = 0; index3 <= target; index3++) {
      result.push(index3);
    }
    return result;
  };
  const getDelay = (i, len) => {
    if (props.stopOrder === "ltr")
      return 0.2 * i;
    return 0.2 * (len - 1 - i);
  };
  const start = () => {
    setRolling(true);
  };
  const reset = () => {
    setRolling(false);
    if (autoStart) {
      (0, import_raf.raf)(() => start());
    }
  };
  (0, import_react.useEffect)(() => {
    if (autoStart) {
      start();
    }
  }, [autoStart]);
  (0, import_react.useImperativeHandle)(ref, () => ({
    start,
    reset
  }));
  return /* @__PURE__ */ import_react.default.createElement("div", {
    className: (0, import_classnames.default)(bem(""), props.className)
  }, targetNumArr.map((_, i) => /* @__PURE__ */ import_react.default.createElement(import_RollingTextItem.default, {
    key: String(i),
    figureArr: isCustomType ? getTextArrByIdx(i) : getFigureArr(i),
    duration,
    direction,
    isStart: rolling,
    height,
    delay: getDelay(i, itemLength)
  })));
});
RollingText.defaultProps = {
  height: 40,
  startNum: 0,
  textList: [],
  duration: 2,
  autoStart: true,
  direction: "down",
  stopOrder: "ltr"
};
var stdin_default = RollingText;
