function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-08-17 09:52:21
 * @LastEditTime: 2021-09-08 15:16:37
 * @FilePath: \annar-master\components\progress-bar\index.tsx
 */
import * as React from 'react';
import classNames from 'classnames';
import Box from '../box';
import Loading from '../loading';
import { getPrefixCls } from './../common';
var prefixCls = getPrefixCls('progress_bar');

var ProgressBar = function ProgressBar(props) {
  var _props$data = props.data,
      data = _props$data === void 0 ? [] : _props$data,
      value = props.value,
      style = props.style;

  var _React$useState = React.useState(false),
      _React$useState2 = _slicedToArray(_React$useState, 2),
      move = _React$useState2[0],
      setMove = _React$useState2[1];

  React.useEffect(function () {
    if (data.length > 1 && !move) {
      setTimeout(function () {
        setMove(true);
      }, 100);
    }
  }, [data]);
  var curIndex = -1;
  data.forEach(function (item, index) {
    if (value === item.key) {
      curIndex = index;
    }
  });
  var moveX = data.length > 0 ? 100 / data.length * (curIndex + 1) : 100;
  return /*#__PURE__*/React.createElement(Box, {
    className: prefixCls,
    style: style
  }, data === null || data === void 0 ? void 0 : data.map(function (item, index) {
    var _classNames;

    return /*#__PURE__*/React.createElement(Box, {
      key: item.key,
      className: classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-node"), true), _defineProperty(_classNames, "".concat(prefixCls, "-node_first"), index === 0), _defineProperty(_classNames, "".concat(prefixCls, "-node_last"), index === curIndex), _defineProperty(_classNames, "".concat(prefixCls, "-node_active"), index <= curIndex), _classNames))
    }, item.value);
  }), data.length === 0 ? /*#__PURE__*/React.createElement(Loading, {
    type: "gap",
    gapColor: "#E8E8E8"
  }) : null, /*#__PURE__*/React.createElement(Box, {
    className: "".concat(prefixCls, "-process"),
    style: {
      width: move ? "".concat(moveX, "%") : 0,
      transition: "width ".concat((curIndex + 1) * 0.3, "s ease-in")
    }
  }));
};

export default ProgressBar;