"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.usePercent = void 0;
var _vue = require("vue");
const AUTO_INTERVAL = 200;
const STEP_BUCKETS = [[30, 0.05], [70, 0.03], [96, 0.01]];
const usePercent = (spinning, percent) => {
  const mockPercent = (0, _vue.ref)(0);
  let mockIntervalRef = null;
  const isAuto = (0, _vue.computed)(() => percent.value === 'auto');
  (0, _vue.watchEffect)(cleanup => {
    if (isAuto.value && spinning.value) {
      mockPercent.value = 0;
      mockIntervalRef = setInterval(() => {
        const prev = mockPercent.value;
        const restPTG = 100 - prev;
        for (let i = 0; i < STEP_BUCKETS.length; i += 1) {
          const [limit, stepPtg] = STEP_BUCKETS[i];
          if (prev <= limit) {
            mockPercent.value = prev + restPTG * stepPtg;
            return;
          }
        }
        mockPercent.value = prev;
      }, AUTO_INTERVAL);
    }
    cleanup(() => {
      clearInterval(mockIntervalRef);
    });
  });
  return (0, _vue.computed)(() => isAuto.value ? mockPercent.value : percent.value);
};
exports.usePercent = usePercent;