import React from 'react';
import PropTypes from 'prop-types';
import { classnames } from '../../helpers/component';

const CURRENCIES = {
    USD: '$',
    EUR: '€',
    CHF: 'CHF'
};

const Price = ({ children: amount = 0, currency = '', className = '', divisor = 100, suffix = '' }) => {
    const value = Number(amount / divisor).toFixed(2);
    const c = <span className="currency">{CURRENCIES[currency] || currency}</span>;
    const p = value < 0 ? <span className="prefix">-</span> : null;
    const v = <span className="amount">{Math.abs(value)}</span>;
    const s = suffix ? <span className="suffix">{suffix}</span> : null;

    if (currency === 'USD') {
        return (
            <span className={classnames(['price', className])} data-currency={currency}>
                {p}
                {c}
                {v}
                {s}
            </span>
        ); // -$2/month
    }

    return (
        <span className={classnames(['price', className])} data-currency={currency}>
            {p}
            {v}
            {currency ? <> {c}</> : null}
            {s}
        </span>
    ); // -2 EUR/month
};

Price.propTypes = {
    currency: PropTypes.string,
    children: PropTypes.number,
    className: PropTypes.string,
    divisor: PropTypes.number,
    suffix: PropTypes.string
};

export default Price;

@@ -294,17 +294,22 @@
   const 
-v
+fixedV
 alue = N
@@ -344,16 +344,128 @@
 xed(2);%0A
+    const absValue = Math.abs(fixedValue);%0A    const value = ~~fixedValue === absValue ? absValue : fixedValue;%0A
     cons
@@ -652,23 +652,13 @@
 t%22%3E%7B
-Math.abs(
 value
-)
 %7D%3C/s

Fix #248 - Display float price with 2 digit at least (#440)