import React, { useContext, useMemo } from 'react';
import clsx from 'clsx';
import { addUnit } from '../utils';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

var Progress = function Progress(props) {
  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('progress', prefixCls),
      bem = _createNamespace[0];

  var background = useMemo(function () {
    return props.inactive ? '#cacaca' : props.color;
  }, [props.inactive, props.color]);

  var renderPivot = function renderPivot() {
    var textColor = props.textColor,
        pivotText = props.pivotText,
        pivotColor = props.pivotColor,
        percentage = props.percentage;
    var text = pivotText != null ? pivotText : percentage + "%";

    if (props.showPivot && text) {
      var style = {
        color: textColor,
        left: +percentage + "%",
        transform: "translate(-" + +percentage + "%,-50%)",
        background: pivotColor || background
      };
      return /*#__PURE__*/React.createElement("span", {
        style: style,
        className: clsx(bem('pivot'))
      }, text);
    }

    return null;
  };

  var trackColor = props.trackColor,
      percentage = props.percentage,
      strokeWidth = props.strokeWidth;
  var rootStyle = {
    background: trackColor,
    height: addUnit(strokeWidth)
  };
  var portionStyle = {
    background: background,
    transform: "scaleX(" + +percentage / 100 + ")"
  };
  return /*#__PURE__*/React.createElement("div", {
    className: clsx(bem()),
    style: rootStyle
  }, /*#__PURE__*/React.createElement("span", {
    className: clsx(bem('portion')),
    style: portionStyle
  }), renderPivot());
};

Progress.defaultProps = {
  showPivot: true,
  percentage: 0
};
export default Progress;