import { ArrowLeftOutlined } from '@ant-design/icons';
import { Button } from 'antd';
import { useNavigate } from 'react-router-dom';

interface PageBackButtonProps {
  text?: string;
  fallbackPath?: string;
  className?: string;
}

const PageBackButton = ({ text = '返回', fallbackPath = '/', className }: PageBackButtonProps) => {
  const navigate = useNavigate();

  const handleBack = () => {
    if (window.history.length > 1) {
      navigate(-1);
      return;
    }
    navigate(fallbackPath);
  };

  return (
    <Button icon={<ArrowLeftOutlined />} onClick={handleBack} className={className}>
      {text}
    </Button>
  );
};

export default PageBackButton;
