import React__default, { useRef, useState, useMemo, useEffect } from 'react';
import { Progress as Progress$1 } from 'antd';

function ProgressComponent({
  status
}) {
  const timer = useRef(null);
  const currentStatus = useRef('loading');
  const [percent, setPersent] = useState(0);
  const isHide = useMemo(() => percent === 100, [percent]);
  useEffect(() => {
    if (percent < 80 && currentStatus.current === 'loading') {
      const num = percent + 20;
      timer.current = setTimeout(() => setPersent(num), 200);
    }
  }, [percent]);
  useEffect(() => {
    if (currentStatus.current !== status) {
      clearTimeout(timer.current);
      currentStatus.current = status;
      const isOver = status === 'error' || status === 'over';
      setPersent(isOver ? 100 : 20);
    }
  }, [status]);
  useEffect(() => {
    return () => clearTimeout(timer.current);
  });
  return /*#__PURE__*/React__default.createElement(Progress$1, {
    status: status === 'error' ? 'exception' : 'active',
    percent: percent,
    showInfo: false,
    strokeWidth: 2,
    strokeColor: status !== 'error' ? 'var(--primary)' : ' var(--danger)',
    className: `lm-c-loading-progress ${isHide ? 'lm-c-loading-progress-over' : ''}`
  });
}
ProgressComponent.defaultProps = {
  status: 'loading'
};
var Progress = /*#__PURE__*/React__default.memo(ProgressComponent);

export { Progress as default };
//# sourceMappingURL=index.js.map
