Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

1020 B
Raw Blame
'use client';

import { usePlanContext } from '@/components/providers/plan-provider';
import {
  type Feature,
  type PlanLimits,
  PLANS,
  hasFeature,
  isWithinLimit,
  getMinimumPlanForFeature,
} from '@/config/plans';

export function useFeatureGate() {
  const { planId, isCloud } = usePlanContext();
  const plan = PLANS[planId] ?? PLANS.starter;

  return {
    planId,
    planName: plan.name,
    isCloud,

    canUse(feature: Feature): boolean {
      return hasFeature(plan, feature);
    },

    withinLimit(
      key: keyof Omit<PlanLimits, 'features' | 'allowedScrapers' | 'allowedModels'>,
      currentCount: number,
    ): boolean {
      return isWithinLimit(plan, key, currentCount);
    },

    getLimit(
      key: keyof Omit<PlanLimits, 'features' | 'allowedScrapers' | 'allowedModels'>,
    ): number {
      return plan.limits[key];
    },

    requiredPlanFor(feature: Feature): string {
      const minPlan = getMinimumPlanForFeature(feature);
      return PLANS[minPlan].name;
    },
  };
}