import _extends from 'babel-runtime/helpers/extends';
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
var _jsxFileName = 'src/progress/LinearProgress.jsx';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

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
};
LinearProgress.defaultProps = {
    prefixCls: 'ne-linear-progress',
    value: 0,
    infoFormat: function infoFormat(percent) {
        return percent + '%';
    },
    showInfo: true,
    indicatorPosition: 'top',
    max: 100,
    min: 0,
    pathProps: {}
};

/**
 * LinearProgress
 */
export default function LinearProgress(props) {
    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,
        other = _objectWithoutProperties(props, ['infoFormat', 'className', 'value', 'max', 'min', 'prefixCls', 'showInfo', 'indicator', 'indicatorPosition', 'strokeWidth', 'duration', 'pathProps', 'pathColor']);

    var classes = classNames(prefixCls, _defineProperty({}, prefixCls + '-success', value === max), className);
    var bgStyle = strokeWidth ? {
        height: strokeWidth
    } : {};
    var indicatorStyles = {
        top: {
            left: value / (max - min) * 100 + '%',
            transform: 'translateX(-' + 50 + '%)',
            bottom: '100%'
        },
        bottom: {
            left: value / (max - min) * 100 + '%',
            transform: 'translateX(-' + 50 + '%)',
            top: '100%'
        },
        left: {
            left: value / (max - min) * 100 + '%',
            transform: 'translateY(-' + 50 + '%)',
            top: '50%'
        },
        right: {
            right: 100 - value / (max - min) * 100 + '%',
            transform: 'translateY(-' + 50 + '%)',
            top: '50%'
        }
    };
    var indicatorStyle = indicatorStyles[indicatorPosition];
    if (duration) indicatorStyles[indicatorPosition].transitionDuration = duration + 'ms';
    var pathStyle = _extends({
        transform: 'scaleX(' + value / (max - min) + ')'
    }, duration ? { transitionDuration: duration + 'ms' } : {}, pathProps.style || {});
    if (pathColor) {
        pathStyle.backgroundColor = pathColor;
    }
    return React.createElement(
        'div',
        Object.assign({ 'aria-valuenow': value, 'aria-valuemin': min, 'aria-valuemax': max, className: classes }, other, {
            __source: {
                fileName: _jsxFileName,
                lineNumber: 107
            },
            __self: this
        }),
        React.createElement(
            'div',
            { className: prefixCls + '-bg', style: bgStyle, __source: {
                    fileName: _jsxFileName,
                    lineNumber: 108
                },
                __self: this
            },
            React.createElement('div', Object.assign({ className: prefixCls + '-bar' }, pathProps, { style: pathStyle, __source: {
                    fileName: _jsxFileName,
                    lineNumber: 109
                },
                __self: this
            })),
            indicator ? React.createElement(
                'div',
                { className: prefixCls + '-indicator', style: indicatorStyle, __source: {
                        fileName: _jsxFileName,
                        lineNumber: 111
                    },
                    __self: this
                },
                indicator(value)
            ) : null
        ),
        showInfo ? React.createElement(
            'div',
            { className: prefixCls + '-info', __source: {
                    fileName: _jsxFileName,
                    lineNumber: 116
                },
                __self: this
            },
            infoFormat(value)
        ) : null
    );
}