"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Context_1 = require("../../Context");
const getComponent_1 = require("../../getComponent");
const react_1 = tslib_1.__importDefault(require("react"));
/**
 * # 🚨 ErrorState
 *
 * Display an error message. Used by UIs when an exception is caught, and an error message
 * needs to be displayed. If in development mode, the actual error is displayed, otherwise
 * displays a generic message in production mode.
 *
 * ## Usage
 * ```jsx
 * <ErrorState retry={retryCallback} error={Error('Bang!')} />
 * ```
 */
class ErrorState extends react_1.default.PureComponent {
    render() {
        const { error, retry } = this.props;
        const BB = this.context;
        const development = BB.Configs.getValue('development');
        const props = {
            description: (development && error) ? error.message : 'An unknown error has occured. Please try again later.',
            title: (development && error) ? error.name : 'Something broke!',
        };
        if (retry) {
            props.actionTitle = 'Retry';
            props.actionOnPress = retry;
        }
        return (react_1.default.createElement(getComponent_1.ComponentState, Object.assign({}, props)));
    }
}
ErrorState.contextType = Context_1.BlueBaseContext;
exports.ErrorState = ErrorState;
