import React from 'react'; import { useSubscription } from '@/contexts/SubscriptionContext'; import { SubscriptionFeatureFlag } from '@/types/subscription'; import { Paywall } from './Paywall'; export interface FeatureGateProps { children: React.ReactNode; feature: SubscriptionFeatureFlag | SubscriptionFeatureFlag[]; fallback?: React.ReactNode; showPaywall?: boolean; paywallTitle?: string; paywallDescription?: string; requiredPlan?: 'basic' | 'professional' | 'enterprise'; } /** * Component that conditionally renders children based on subscription features */ export const FeatureGate = ({ children, feature, fallback = null, showPaywall = false, paywallTitle, paywallDescription, requiredPlan, }: FeatureGateProps) => { const { canAccessFeature } = useSubscription(); const features = Array.isArray(feature) ? feature : [feature]; const hasAccess = features.every((f) => canAccessFeature(f)); if (!hasAccess) { if (showPaywall) { return ( ); } return <>{fallback}; } return <>{children}; };