import { useEffect, useState } from 'react';
import './App.less';

import { GetroutesDyamic } from '@/routes/index';
import { ErrorBoundary } from '@/common/errorBoundary';
import { ErrorFallback } from '@/common/errorBoundary/ErrorFallback';
import MakeError from '@/common/errorBoundary/error/MakeError';

function App() {
  const [token, setToken] = useState('');

  useEffect(() => {
    const userToken = localStorage.getItem('kiwi.token');
    if (userToken) {
      setToken(userToken);
    } else {
      setToken('');
    }
  }, []);

  const [hasError, setHasError] = useState(false);
  const onError = (error) => {
    // 日志上報
    console.log(error);
    setHasError(true);
  };

  const onReset = () => {
    console.log('尝试恢复错误');
    setHasError(false);
  };

  return (
    <ErrorBoundary
      fallbackRender={(fallbackProps) => <ErrorFallback {...fallbackProps} />}
      onError={onError}
      onReset={onReset}
    >
      <GetroutesDyamic />
    </ErrorBoundary>
  );
}

export default App;
