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 __());
    };
})();
import * as classnames from "classnames";
import * as numeral from "numeral";
import * as React from "react";
import * as PropTypes from "prop-types";
import * as shortNumber from "short-number";
var propTypes = {
    children: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
    className: PropTypes.string,
    short: PropTypes.bool,
};
export var cssClass = {
    CONTAINER: "Number",
};
/**
 * Provides consistent number formatting for long numbers (e.g. 4123456 -> 4,123,456), with optional
 * shortening (e.g. 4123456 -> 4.1M).
 */
var Number = /** @class */ (function (_super) {
    __extends(Number, _super);
    function Number() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Number.format = function (num, short) {
        if (short === void 0) { short = false; }
        var rawNumber = parseInt("" + (num || 0), 10);
        if (isNaN(rawNumber)) {
            throw new Error("A number is required.");
        }
        return short ? shortNumber(rawNumber) : numeral(rawNumber).format("0,0");
    };
    Number.prototype.render = function () {
        var format = Number.format;
        var _a = this.props, children = _a.children, className = _a.className, short = _a.short;
        return (React.createElement("span", { className: classnames(cssClass.CONTAINER, className) }, format(children, short)));
    };
    Number.propTypes = propTypes;
    return Number;
}(React.PureComponent));
export default Number;
