import React from 'react';
import { observer } from 'mobx-react-lite';
import { ErrorState } from '../ErrorState';
import { CollectionEmptyState } from '../EmptyState/CollectionEmptyState';
import { CollectionNoResultsState } from '../EmptyState/CollectionNoResultsState';
function _PlaceholderStatesBase(props) {
    const { state, emptyState, noResultsState: noResultsStateProp, errorState, children, loadingState, } = props;
    const { initTask, showLoadingState, showEmptyState, hasAvailableItems, resultOriginQuerySearch, hasNonPersistentActiveFilters, showErrorState, errorStatus, } = state;
    const noResultsState = typeof noResultsStateProp === 'function'
        ? noResultsStateProp()
        : noResultsStateProp;
    let child;
    if (initTask.status.isError) {
        child = (React.createElement(ErrorState, { dataHook: "placeholder-states-error-state", errorStatus: initTask.status, state: state, errorState: errorState }));
    }
    else if (showLoadingState) {
        child = loadingState || children;
    }
    else if (showErrorState && errorStatus) {
        child = (React.createElement(ErrorState, { dataHook: "placeholder-states-error-state", errorStatus: errorStatus, state: state, errorState: errorState }));
    }
    else if (showEmptyState) {
        if (hasAvailableItems &&
            (resultOriginQuerySearch != null || hasNonPersistentActiveFilters)) {
            if (noResultsState) {
                child = noResultsState;
            }
            else {
                child = React.createElement(CollectionNoResultsState, null);
            }
        }
        else {
            if (emptyState) {
                child = emptyState;
            }
            else {
                child = React.createElement(CollectionEmptyState, null);
            }
        }
    }
    else {
        child = children;
    }
    return React.createElement(React.Fragment, null, child);
}
export const PlaceholderStatesBase = observer(_PlaceholderStatesBase);
//# sourceMappingURL=PlaceholderStatesBase.js.map