import React from "react";
import {BrowserRouter, HashRouter, Navigate, Route, Routes, useNavigate} from "react-router-dom";
import {APP_CONFIG} from "../config.ts";
import {Button} from "@douyinfe/semi-ui";
import DefaultPage from "./index";
import {Result} from "../components/Result.tsx";

const routerMode: 'browser' | 'hash' | string = APP_CONFIG.ROUTER_MODE;

const WebRouter: React.FC<{
    children?: React.ReactNode
}> = (prop) => (
    routerMode == 'hash' ? <HashRouter>{prop.children}</HashRouter> : <BrowserRouter>{prop.children}</BrowserRouter>
)

const NotFound: React.FC = () => {
    const navigate = useNavigate();
    return <Result
        status="404"
        title="页面不存在或无法找到所请求的资源"
        // subTitle="Sorry, the page you visited does not exist."
        extra={<Button onClick={() => navigate('/')} type="primary">返回首页</Button>}/>
}
export const AppRouter = () => (<WebRouter>
    <div className="page-body-content">
        <Routes>
            <Route path="/" element={<DefaultPage/>}/>
            <Route path="*" element={<NotFound/>}/>
        </Routes>
    </div>
</WebRouter>)
