"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.cssClass = void 0;
var classnames = require("classnames");
var numeral = require("numeral");
var React = require("react");
var PropTypes = require("prop-types");
var propTypes = {
    children: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
    className: PropTypes.string,
    zeroIsFree: PropTypes.bool,
    alwaysShowCents: PropTypes.bool,
};
exports.cssClass = {
    CONTAINER: "DollarAmount",
};
/**
 * Provides consistent dollar value formatting (e.g. 4123456 -> $4,123,456)
 */
var DollarAmount = /** @class */ (function (_super) {
    __extends(DollarAmount, _super);
    function DollarAmount() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    DollarAmount.format = function (number, zeroIsFree, alwaysShowCents) {
        if (zeroIsFree === void 0) { zeroIsFree = false; }
        if (alwaysShowCents === void 0) { alwaysShowCents = false; }
        var rawNumber = parseFloat(number || 0);
        if (isNaN(rawNumber)) {
            throw new Error("A number is required.");
        }
        if (rawNumber === 0 && zeroIsFree) {
            return "Free";
        }
        var format = alwaysShowCents ? "$0,0.00" : "$0,0[.]00";
        return numeral(rawNumber).format(format);
    };
    DollarAmount.prototype.render = function () {
        var format = DollarAmount.format;
        var _a = this.props, children = _a.children, className = _a.className, zeroIsFree = _a.zeroIsFree, alwaysShowCents = _a.alwaysShowCents;
        return (React.createElement("span", { className: classnames(exports.cssClass.CONTAINER, className) }, format(children, zeroIsFree, alwaysShowCents)));
    };
    DollarAmount.propTypes = propTypes;
    return DollarAmount;
}(React.PureComponent));
exports.default = DollarAmount;
