"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Context_1 = require("./Context");
const react_1 = tslib_1.__importDefault(require("react"));
/**
 * Resolves a component from BlueBase context, and returns it.
 * It is possible to pass multiple keys as backup. So if one component
 * is not found, the function will fallback and try to find next component.
 *
 * @param keys
 */
function getComponent(...keys) {
    if (keys.length === 0) {
        throw Error('getComponent method needs at least one key');
    }
    const displayName = keys.join('_');
    const BlueBaseComponent = (props) => (react_1.default.createElement(Context_1.BlueBaseConsumer, { children: (BB) => {
            if (!BB) {
                // tslint:disable-next-line: max-line-length
                throw Error(`Could not resolve component "${displayName}" in "getComponent" command. Reason: BlueBase context not found.`);
            }
            const Component = BB.Components.resolve(...keys);
            return react_1.default.createElement(Component, props);
        } }));
    BlueBaseComponent.displayName = displayName;
    return BlueBaseComponent;
}
exports.getComponent = getComponent;
// System Components
exports.BlueBaseContent = getComponent('BlueBaseContent');
exports.BlueBaseFilter = getComponent('BlueBaseFilter');
exports.ComponentState = getComponent('ComponentState');
exports.DataObserver = getComponent('DataObserver');
exports.DynamicIcon = getComponent('DynamicIcon');
exports.EmptyState = getComponent('EmptyState');
exports.ErrorObserver = getComponent('ErrorObserver');
exports.ErrorState = getComponent('ErrorState');
exports.FormattedMessage = getComponent('FormattedMessage');
exports.Header = getComponent('Header');
exports.HeaderTitle = getComponent('HeaderTitle');
exports.HeaderBackButton = getComponent('HeaderBackButton');
exports.HoverObserver = getComponent('HoverObserver');
exports.Link = getComponent('Link');
exports.LoadingState = getComponent('LoadingState');
exports.Noop = getComponent('Noop');
exports.PluginIcon = getComponent('PluginIcon');
exports.Navigation = getComponent('Navigation');
exports.NavigationActions = getComponent('NavigationActions');
exports.Redirect = getComponent('Redirect');
exports.StatefulComponent = getComponent('StatefulComponent');
exports.WaitObserver = getComponent('WaitObserver');
// Native
exports.ActivityIndicator = getComponent('ActivityIndicator');
exports.Button = getComponent('Button');
exports.Image = getComponent('Image');
exports.Text = getComponent('Text');
exports.View = getComponent('View');
// Typography
exports.H1 = getComponent('H1');
exports.H2 = getComponent('H2');
exports.H3 = getComponent('H3');
exports.H4 = getComponent('H4');
exports.H5 = getComponent('H5');
exports.H6 = getComponent('H6');
exports.Subtitle1 = getComponent('Subtitle1');
exports.Subtitle2 = getComponent('Subtitle2');
exports.Body1 = getComponent('Body1');
exports.Body2 = getComponent('Body2');
exports.Caption = getComponent('Caption');
exports.Overline = getComponent('Overline');
