import { ReactNode } from 'react';
import { useHasCapability, useHasAnyCapability } from './useCapability';

interface CapabilityGateProps {
  /** Single capability required */
  capability?: string;
  /** Multiple capabilities — user needs at least one */
  anyOf?: string[];
  /** Content shown when user has the capability */
  children: ReactNode;
  /** Optional fallback shown when user lacks the capability */
  fallback?: ReactNode;
}

export function CapabilityGate({ capability, anyOf, children, fallback = null }: CapabilityGateProps) {
  const hasSingle = useHasCapability(capability || '');
  const hasAny = useHasAnyCapability(...(anyOf || []));

  const allowed = capability ? hasSingle : anyOf ? hasAny : true;

  return allowed ? <>{children}</> : <>{fallback}</>;
}
