import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
	Progress as SemanticProgress
} from 'semantic-ui-react';

import * as styles from './Style.less';

export default class Progress extends Component {
	static propTypes = {
		percent: PropTypes.oneOfType([
			PropTypes.number,
			PropTypes.bool
		]),
		total: PropTypes.oneOfType([
			PropTypes.number,
			PropTypes.bool
		]),
		value: PropTypes.oneOfType([
			PropTypes.number,
			PropTypes.bool
		])
	};

	static defaultProps = {
		percent: 0,
		total: false,
		value: false
	};

	render() {
		const props = {};

		if (this.props.percent) {
			props.percent = this.props.percent * 100;
		} else if (this.props.total && this.props.value) {
			props.total = this.props.total;
			props.value = this.props.value;
		}

		return (
			<SemanticProgress
				className={styles.Progress}
				progress="percent"
				autoSuccess
				precision={0}
				{...props}
			/>
		);
	}
}
