import React from 'react';

export default function(props) {
    if (props.error) {
        if (process.env.NODE_ENV === 'development') {
            throw new Error(props.error.stack);
        } else {
            return (
                <div>
                    <div>
                        <div>发现错误：</div>
                        <div>
                            {props.error.stack.split('\n').map((e, i) => (
                                <div
                                    style={{
                                        marginLeft: i > 0 ? '3em' : 0,
                                    }}
                                >
                                    {e}
                                </div>
                            ))}
                        </div>
                    </div>
                    <button onClick={props.retry}>重试</button>
                </div>
            );
        }
    } else if (props.timedOut) {
        // When the loader has taken longer than the timeout
        return (
            <div>
                加载超时... <button onClick={props.retry}>重试</button>
            </div>
        );
    } else if (props.pastDelay) {
        // When the loader has taken longer than the delay
        return <div>Loading...</div>;
    } else {
        // When the loader has just started
        return null;
    }
}
