//
// Copyright 2023 DXOS.org
//
import React, { Component } from 'react';
// import { useNavigate } from 'react-router-dom';
// import { Button, Message } from '@dxos/react-ui';
import { log } from '@dxos/log';
const ErrorPopup = ({ error, onReset }) => {
    return React.createElement("div", null, error.message);
    // const navigate = useNavigate();
    // const message = String(error);
    // const stack = error.stack;
    // const handleCopyError = useCallback(() => {
    //   void navigator.clipboard.writeText(JSON.stringify({ message, stack }));
    // }, [message, stack]);
    // return (
    //   <div className='m-4'>
    //     <Message.Root valence='error' className='mlb-4'>
    //       <Message.Title>{message}</Message.Title>
    //       <pre className='text-xs overflow-auto max-is-72 max-bs-72'>{stack}</pre>
    //     </Message.Root>
    //     <div role='none' className='flex gap-2'>
    //       <div className='grow' />
    //       <Button onClick={handleCopyError} classNames='gap-2'>
    //         <span>Copy Error</span>
    //         <Clipboard weight='duotone' />
    //       </Button>
    //       <Button
    //         variant='primary'
    //         onClick={async () => {
    //           navigate?.('/');
    //           onReset?.();
    //         }}
    //       >
    //         <span>Reset</span>
    //       </Button>
    //     </div>
    //   </div>
    // );
};
/**
 * Error boundary.
 * https://reactjs.org/docs/error-boundaries.html
 */
export class ErrorBoundary extends Component {
    constructor(props) {
        super(props);
        this.state = { hasError: false };
    }
    static getDerivedStateFromError(error) {
        log.catch(error);
        return { hasError: true, error };
    }
    render() {
        if (this.state.hasError) {
            return (React.createElement(ErrorPopup, { error: this.state.error, onReset: () => {
                    this.setState({ hasError: false });
                } }));
        }
        return this.props.children;
    }
}
//# sourceMappingURL=ErrorBoundary.js.map