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 React from 'react';
import PropTypes from 'prop-types';
var defaultErrorMessageComponent = function (_a) {
    var error = _a.error, errorInfo = _a.errorInfo;
    return (React.createElement("div", null,
        React.createElement("h2", null, "Something went wrong."),
        React.createElement("details", { style: {
                whiteSpace: 'pre-wrap',
            } },
            error && error.toString(),
            React.createElement("br", null),
            errorInfo.componentStack)));
};
defaultErrorMessageComponent.propTypes = {
    error: PropTypes.any,
    errorInfo: PropTypes.any,
};
// Component based on https://blog.pusher.com/react-error-boundaries/
var ErrorBoundary = /** @class */ (function (_super) {
    __extends(ErrorBoundary, _super);
    function ErrorBoundary(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            hasError: false,
            error: null,
            errorInfo: null,
        };
        return _this;
    }
    ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
        this.setState({
            hasError: true,
            error: error,
            errorInfo: errorInfo,
        });
    };
    ErrorBoundary.prototype.render = function () {
        var ErrorMessageComponent = this.props.ErrorMessageComponent;
        if (this.state.hasError) {
            return (React.createElement(ErrorMessageComponent, { error: this.state.error, errorInfo: this.state.errorInfo }));
        }
        return this.props.children;
    };
    return ErrorBoundary;
}(React.Component));
export { ErrorBoundary };
ErrorBoundary.propTypes = {
    children: PropTypes.node.isRequired,
    ErrorMessageComponent: PropTypes.any,
};
ErrorBoundary.defaultProps = {
    ErrorMessageComponent: defaultErrorMessageComponent,
};
export default ErrorBoundary;
//# sourceMappingURL=ErrorBoundary.js.map