import { history } from '@umijs/max';
import { Button, Result } from 'antd';
import { useEffect, useState } from 'react';

export default function Page() {
	const [countdown, setCountdown] = useState(5);

	useEffect(() => {
		if (countdown === 0) {
			history.push('/');
			return;
		}

		const timerId = setTimeout(() => {
			setCountdown(countdown - 1);
		}, 1000);

		return () => clearTimeout(timerId);
	}, [countdown]);

	return (
		<Result
			status={404}
			title={'抱歉，你访问的页面不存在'}
			subTitle={`页面将在 ${countdown} 秒后跳转至首页`}
			extra={
				<Button type="primary" onClick={() => history.push('/')}>
					返回首页
				</Button>
			}
		/>
	);
}
