import React from 'react';
import i18n from 'ui-i18n';
import { LinearLoadIndicator } from '../LinearLoadIndicator';
import { EmptySearchResult } from '../EmptySearchResult';
import { ErrorBoundary } from '../ErrorBoundary';
import { EMPTY_STATE_ICONS, EMPTY_STATE_VARIANTS, EmptyState } from '../EmptyState';
import { RequestStates } from '../types';
import styles from './RequestedData.module.css';
export var RequestedData = function (_a) {
    var requestState = _a.requestState, isResponseEmpty = _a.isResponseEmpty, children = _a.children, DataLoadedComponent = _a.DataLoadedComponent, _b = _a.DataLoadingComponent, DataLoadingComponent = _b === void 0 ? RequestedDataLoading : _b, _c = _a.DataErrorComponent, DataErrorComponent = _c === void 0 ? RequestedDataError : _c;
    switch (requestState) {
        case RequestStates.LOADED:
            return DataLoadedComponent ? (React.createElement(DataLoadedComponent, null)) : (React.createElement(RequestedDataLoaded, { isResponseEmpty: isResponseEmpty }, children));
        case RequestStates.ERROR:
            return React.createElement(DataErrorComponent, null);
        case RequestStates.LOADING:
        default:
            return React.createElement(DataLoadingComponent, null);
    }
};
var RequestedDataError = function () { return (React.createElement(EmptyState, { LogoRenderer: EMPTY_STATE_ICONS.ERROR, text: i18n.text('Something went wrong'), variant: EMPTY_STATE_VARIANTS.full })); };
var RequestedDataLoaded = function (_a) {
    var isResponseEmpty = _a.isResponseEmpty, children = _a.children;
    return isResponseEmpty ? (React.createElement(EmptySearchResult, { variant: "noData", className: styles.noData })) : (React.createElement(ErrorBoundary, { error: React.createElement(RequestedDataError, null) }, children));
};
var RequestedDataLoading = function () { return React.createElement(LinearLoadIndicator, null); };
