import { __assign, __rest } from "tslib";
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { strokePresetColors } from './types';
var Bar = function (props) {
    var _a, _b;
    var _c = props.percent, percent = _c === void 0 ? 0 : _c, _d = props.showInfo, showInfo = _d === void 0 ? true : _d, _e = props.strokeWidth, strokeWidth = _e === void 0 ? 8 : _e, _f = props.strokeLinecap, strokeLinecap = _f === void 0 ? 'round' : _f, _g = props.strokeColor, strokeColor = _g === void 0 ? 'primary' : _g, _h = props.innerText, innerText = _h === void 0 ? false : _h, customisedCls = props.prefixCls, format = props.format, backgroundType = props.backgroundType, className = props.className, style = props.style, otherProps = __rest(props, ["percent", "showInfo", "strokeWidth", "strokeLinecap", "strokeColor", "innerText", "prefixCls", "format", "backgroundType", "className", "style"]);
    var percentage = percent > 100 ? 100 : percent;
    percentage = percentage < 0 ? 0 : percentage;
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('progress-bar', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className, prefixCls + "_" + strokeLinecap);
    var strokeBgCls = classNames(prefixCls + "__bg", (_a = {},
        _a[prefixCls + "__bg_" + strokeColor] = !Array.isArray(strokeColor) && strokePresetColors.includes(strokeColor),
        _a));
    var background = Array.isArray(strokeColor)
        ? "linear-gradient(to right, " + strokeColor.join(',') + ")"
        : strokePresetColors.includes(strokeColor)
            ? ''
            : strokeColor;
    var effectCls = classNames(prefixCls + "__effect", (_b = {},
        _b[prefixCls + "__effect_" + backgroundType] = backgroundType,
        _b));
    var _renderLabel = function () {
        if (showInfo && !innerText) {
            return format ? (format(percentage)) : (React.createElement("span", { className: prefixCls + "__text" },
                percentage,
                "%"));
        }
        return null;
    };
    var _renderInnerLabel = function () {
        if (showInfo && innerText) {
            return format ? (format(percentage)) : (React.createElement("div", { className: prefixCls + "__inner-text", style: { lineHeight: strokeWidth + "px" } },
                percentage,
                "%"));
        }
        return null;
    };
    return (React.createElement("div", __assign({}, otherProps, { role: "progressbar", "aria-valuemax": 100, "aria-valuemin": 0, "aria-valuenow": percentage, className: cls, style: style }),
        React.createElement("div", { className: prefixCls + "__inner", style: { height: strokeWidth } },
            React.createElement("div", { className: strokeBgCls, style: {
                    width: percentage + "%",
                    background: background,
                } },
                React.createElement("div", { className: effectCls }),
                _renderInnerLabel())),
        _renderLabel()));
};
Bar.displayName = 'Bar';
export default Bar;
//# sourceMappingURL=bar.js.map