'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _TooltipTrigger = require('../TooltipTrigger');

var _TooltipTrigger2 = _interopRequireDefault(_TooltipTrigger);

var _Progress = require('./Progress.scss');

var _Progress2 = _interopRequireDefault(_Progress);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function normalize(percent) {
	if (percent > 100) {
		return 100;
	}
	if (percent < 0) {
		return 0;
	}
	return percent;
}

function Progress(_ref) {
	var _classNames;

	var id = _ref.id,
	    percent = _ref.percent,
	    tooltip = _ref.tooltip,
	    infinite = _ref.infinite,
	    contained = _ref.contained;

	var normalizedPercent = infinite ? 100 : normalize(percent);
	var style = { width: normalizedPercent + '%' };

	var rootClassNames = (0, _classnames2.default)(_Progress2.default.progress, (_classNames = {}, _defineProperty(_classNames, _Progress2.default.hidden, normalizedPercent === 0), _defineProperty(_classNames, _Progress2.default.fixed, !contained), _defineProperty(_classNames, _Progress2.default.infinite, infinite), _classNames));

	var progress = _react2.default.createElement(
		'div',
		{ style: style, className: _Progress2.default['progress-percent'] },
		infinite && _react2.default.createElement('div', { className: _Progress2.default['infinite-indicator'] })
	);

	if (tooltip) {
		progress = _react2.default.createElement(
			_TooltipTrigger2.default,
			{ label: tooltip, tooltipPlacement: 'bottom' },
			progress
		);
	}

	return _react2.default.createElement(
		'div',
		{ id: id, className: rootClassNames },
		progress
	);
}

Progress.propTypes = {
	id: _react.PropTypes.string,
	percent: _react.PropTypes.number,
	tooltip: _react.PropTypes.string,
	infinite: _react.PropTypes.bool,
	contained: _react.PropTypes.bool
};

exports.default = Progress;