import React from 'react';
import { Result } from 'antd';
import { usePermission } from '../hooks/usePermission';

interface PermissionRouteProps {
  permission: string;
  children: React.ReactNode;
}

const PermissionRoute: React.FC<PermissionRouteProps> = ({ permission, children }) => {
  const { hasPermission } = usePermission();
  if (!hasPermission(permission)) {
    return <Result status="403" title="无权访问" subTitle="您没有访问此页面的权限" />;
  }
  return <>{children}</>;
};

export default PermissionRoute;
