import React from 'react';
import { Button } from 'antd';
import type { ButtonProps } from 'antd';
import { usePermission } from '../hooks/usePermission';

interface PermissionButtonProps extends ButtonProps {
  permission: string;
  children: React.ReactNode;
}

const PermissionButton: React.FC<PermissionButtonProps> = ({
  permission,
  children,
  ...btnProps
}) => {
  const { hasPermission } = usePermission();
  if (!hasPermission(permission)) return null;
  return <Button {...btnProps}>{children}</Button>;
};

export default PermissionButton;
