import type { FC } from 'react';
import React from 'react';
import { ErrorMessage, LoadingPageIndicator } from '@theorchard/suite-components';

const CLASSNAME = 'PageView';

interface Props {
    children?: React.ReactNode;
    loading: boolean;
    error?: Error;
    hasData: boolean;
    showContentWhenEmpty?: boolean;
}

const PageView: FC<Props> = ({ children, loading, error, hasData, showContentWhenEmpty }) => (
    <div className={CLASSNAME} data-testid={CLASSNAME}>
        {error && <ErrorMessage error={error} />}
        {!error && loading && !hasData && <LoadingPageIndicator />}
        {hasData && children}
        {!error && !loading && !hasData && showContentWhenEmpty && children}
    </div>
);

export default PageView;
