import React, { FC, ReactNode } from 'react';
import { CustomSpin } from './CustomSpin';
import { WithError } from './WithError';

type LoaderProps = {
    children?: ReactNode;
    isLoading?: boolean;
    errorData?: any;
    refresh?: () => void;
};

export const Loader: FC<LoaderProps> = ({
    children,
    isLoading,
    errorData,
    refresh
}) => {
    if (isLoading) {
        return <CustomSpin />
    }

    return (
        <WithError
            errorData={errorData}
            refresh={refresh}
        >
            {children}
        </WithError>
    );
};
