import React from 'react'
import PropTypes from 'prop-types'
import BEMModule from 'utils/bem'
import styles from './style.scss'

const bem = new BEMModule(styles)

const StockValueChange = ({className, percent, size, value}) => {
    const isPositiveChange = percent > 0
    const isNegativeChange = percent < 0
    const stockValueChangeClasses = bem.classNames(
        'c-stock-value-change',
        {small: size === 'small'},
        className
    )
    const changeValueClassNames = bem.classNames(
        'c-stock-value-change__value',
        {
            positive: isPositiveChange,
            negative: isNegativeChange,
        }
    )
    const changePercentageClassNames = bem.classNames(
        'c-stock-value-change__percentage',
        {
            positive: isPositiveChange,
            negative: isNegativeChange,
        }
    )

    return (
        <span className={stockValueChangeClasses}>
            <span className={changeValueClassNames}>{`${value}`}</span>&nbsp;
            <span
                className={changePercentageClassNames}
            >{`(${percent}%)`}</span>
        </span>
    )
}

StockValueChange.propTypes = {
    className: PropTypes.string,
    percent: PropTypes.number,
    size: PropTypes.string,
    value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
}

export default StockValueChange
