import _extends from "@babel/runtime/helpers/esm/extends";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
/**
 * LinearProgress
 */

export default function LinearProgress(props) {
  var _classNames;

  var infoFormat = props.infoFormat,
      className = props.className,
      value = props.value,
      max = props.max,
      min = props.min,
      prefixCls = props.prefixCls,
      showInfo = props.showInfo,
      indicator = props.indicator,
      indicatorPosition = props.indicatorPosition,
      strokeWidth = props.strokeWidth,
      duration = props.duration,
      pathProps = props.pathProps,
      pathColor = props.pathColor,
      color = props.color,
      other = _objectWithoutProperties(props, ["infoFormat", "className", "value", "max", "min", "prefixCls", "showInfo", "indicator", "indicatorPosition", "strokeWidth", "duration", "pathProps", "pathColor", "color"]);

  var classes = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-color-").concat(color), value !== max), _defineProperty(_classNames, "".concat(prefixCls, "-color-success"), value === max), _classNames), className);
  var bgStyle = strokeWidth ? {
    height: strokeWidth
  } : {};
  var indicatorStyles = {
    top: {
      left: "".concat(value / (max - min) * 100, "%"),
      transform: "translateX(-".concat(50, "%)"),
      bottom: '100%'
    },
    bottom: {
      left: "".concat(value / (max - min) * 100, "%"),
      transform: "translateX(-".concat(50, "%)"),
      top: '100%'
    },
    left: {
      left: "".concat(value / (max - min) * 100, "%"),
      transform: "translateY(-".concat(50, "%)"),
      top: '50%'
    },
    right: {
      right: "".concat(100 - value / (max - min) * 100, "%"),
      transform: "translateY(-".concat(50, "%)"),
      top: '50%'
    }
  };
  var indicatorStyle = indicatorStyles[indicatorPosition];
  if (duration) indicatorStyles[indicatorPosition].transitionDuration = "".concat(duration, "ms");

  var pathStyle = _objectSpread({
    transform: "scaleX(".concat(value / (max - min), ")")
  }, duration ? {
    transitionDuration: "".concat(duration, "ms")
  } : {}, pathProps.style || {});

  if (pathColor) {
    pathStyle.backgroundColor = pathColor;
  }

  return React.createElement("div", _extends({
    "aria-valuenow": value,
    "aria-valuemin": min,
    "aria-valuemax": max,
    className: classes
  }, other), React.createElement("div", {
    className: "".concat(prefixCls, "-bg"),
    style: bgStyle
  }, React.createElement("div", _extends({
    className: "".concat(prefixCls, "-path")
  }, pathProps, {
    style: pathStyle
  })), indicator ? React.createElement("div", {
    className: "".concat(prefixCls, "-indicator"),
    style: indicatorStyle
  }, indicator(value)) : null), showInfo ? React.createElement("div", {
    className: "".concat(prefixCls, "-info")
  }, infoFormat(value)) : null);
}
LinearProgress.propTypes = {
  prefixCls: PropTypes.string,
  className: PropTypes.string,

  /** 当前值 */
  value: PropTypes.number,

  /** 最大值 */
  max: PropTypes.number,

  /** 最小值 */
  min: PropTypes.number,

  /** 进度信息 function(percent) => info: ReactNode */
  infoFormat: PropTypes.func,

  /** 是否显示进度信息 */
  showInfo: PropTypes.bool,

  /** 是否显示指示游标 */
  indicator: PropTypes.func,

  /** 指示游标显示位置 */
  indicatorPosition: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),

  /** 宽度 */
  strokeWidth: PropTypes.number,

  /** 过渡动画时长 */
  duration: PropTypes.number,

  /** 进度条属性 */
  pathProps: PropTypes.object,

  /** 进度条颜色 */
  pathColor: PropTypes.string,
  color: PropTypes.oneOf(['primary', 'success', 'warning', 'info', 'error'])
};
LinearProgress.defaultProps = {
  prefixCls: 'ne-linear-progress',
  value: 0,
  infoFormat: function infoFormat(percent) {
    return "".concat(percent, "%");
  },
  showInfo: true,
  indicatorPosition: 'top',
  max: 100,
  min: 0,
  pathProps: {},
  color: 'primary'
};