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 React from "react";
import * as PropTypes from "prop-types";
import Number from "../Number";
var propTypes = {
    children: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
    className: PropTypes.string,
    plural: PropTypes.string,
    singular: PropTypes.string.isRequired,
    short: PropTypes.bool,
    zeroOverride: PropTypes.string,
};
export var cssClass = {
    CONTAINER: "Count",
};
/**
 * Provides a convenient wrapper for displaying counts of things.
 * Renders a span containing a formatted number, using the `Number` component, followed by the given
 * singular or plural form of the subject, depending on the number.
 *
 * Specify a `zeroOverride` to provide an override message to be displayed in the zero case.
 *
 * Usage:
 *   const things = [1, 2, 3];
 *   <Count number={things.length} singular="thing">things</Count>
 *   // results in:
 *   <span>3 things</span>
 */
var Count = /** @class */ (function (_super) {
    __extends(Count, _super);
    function Count() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Count.format = function (_a) {
        var number = _a.number, plural = _a.plural, short = _a.short, singular = _a.singular, zeroOverride = _a.zeroOverride;
        var displayNumber = Number.format(number, short);
        var rawNumber = parseInt("" + number || "0", 10);
        if (rawNumber === 1) {
            return displayNumber + " " + singular;
        }
        if (rawNumber === 0 && zeroOverride) {
            return zeroOverride;
        }
        var defaultPlural = singular + "s";
        return displayNumber + " " + (plural || defaultPlural);
    };
    Count.prototype.render = function () {
        var format = Count.format;
        var _a = this.props, children = _a.children, className = _a.className, plural = _a.plural, short = _a.short, singular = _a.singular, zeroOverride = _a.zeroOverride;
        return (React.createElement("span", { className: classnames(cssClass.CONTAINER, className) }, format({ number: children, plural: plural, short: short, singular: singular, zeroOverride: zeroOverride })));
    };
    Count.propTypes = propTypes;
    return Count;
}(React.PureComponent));
export default Count;
