import React from 'react';
import classnames from 'classnames';
import { strokePresetColors } from '.';
var defaultProps = {
    prefixCls: 'ty-progress-bar',
    percent: 0,
    showInfo: true,
    strokeWidth: 8,
    strokeLinecap: 'round',
    strokeColor: 'primary',
    innerText: false,
};
var Bar = function (props) {
    var _a, _b;
    var percent = props.percent, format = props.format, showInfo = props.showInfo, innerText = props.innerText, strokeWidth = props.strokeWidth, strokeColor = props.strokeColor, strokeLinecap = props.strokeLinecap, backgroundType = props.backgroundType, prefixCls = props.prefixCls, className = props.className, style = props.style;
    var percentage = percent > 100 ? 100 : percent;
    percentage = percentage < 0 ? 0 : percentage;
    var cls = classnames(prefixCls, className, prefixCls + "_" + strokeLinecap);
    var strokeBgCls = classnames(prefixCls + "__bg", (_a = {},
        _a[prefixCls + "__bg_" + strokeColor] = (typeof strokeColor === 'string') &&
            strokePresetColors.includes(strokeColor),
        _a));
    var background = (typeof strokeColor === 'string') ?
        (strokePresetColors.includes(strokeColor) ? '' : strokeColor) :
        "linear-gradient(to right, " + strokeColor.join(',') + ")";
    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", { 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.defaultProps = defaultProps;
export default Bar;
//# sourceMappingURL=bar.js.map