import { usePage } from '@inertiajs/react';

/**
 * Whether a feature flag a module declared (its provider's features()) is on for the
 * signed-in user. rutatiina/core shares the flags that are on; administrators turn
 * them on or off with rutatiina/features.
 */
export function useFeature(name: string): boolean {
  const { features } = usePage().props;

  return (features ?? []).includes(name);
}
