{"version":3,"file":"withFeatureFlag.mjs","sources":["../../../src/lib/flags/withFeatureFlag.tsx"],"sourcesContent":["import { type ComponentType } from 'react';\nimport type { JSX } from 'react';\nimport { useFeatureFlag } from './useFeatureFlag';\nimport type { FlagKey } from './flag-keys';\n\ninterface WithFeatureFlagOptions {\n  /** The feature flag to check */\n  flag: FlagKey | string;\n  /** Component to render when flag is disabled */\n  fallback?: ComponentType;\n}\n\n/**\n * HOC to gate components by feature flag.\n */\nexport function withFeatureFlag<P extends object>(\n  Component: ComponentType<P>,\n  options: WithFeatureFlagOptions\n): ComponentType<P> {\n  const { flag, fallback: FallbackComponent } = options;\n\n  return function WithFeatureFlag(props: P): JSX.Element | null {\n    const isEnabled = useFeatureFlag(flag);\n\n    if (!isEnabled) {\n      return FallbackComponent !== undefined ? <FallbackComponent /> : null;\n    }\n\n    return <Component {...props} />;\n  };\n}\n\n/**\n * HOC to invert the feature flag check (show when flag is disabled).\n */\nexport function withoutFeatureFlag<P extends object>(\n  Component: ComponentType<P>,\n  options: WithFeatureFlagOptions\n): ComponentType<P> {\n  const { flag, fallback: FallbackComponent } = options;\n\n  return function WithoutFeatureFlag(props: P): JSX.Element | null {\n    const isEnabled = useFeatureFlag(flag);\n\n    if (isEnabled) {\n      return FallbackComponent !== undefined ? <FallbackComponent /> : null;\n    }\n\n    return <Component {...props} />;\n  };\n}\n"],"names":["withFeatureFlag","Component","options","flag","FallbackComponent","props","useFeatureFlag","jsx","withoutFeatureFlag"],"mappings":";;;AAeO,SAASA,EACdC,GACAC,GACkB;AAClB,QAAM,EAAE,MAAAC,GAAM,UAAUC,EAAA,IAAsBF;AAE9C,SAAO,SAAyBG,GAA8B;AAG5D,WAFkBC,EAAeH,CAAI,IAM9B,gBAAAI,EAACN,GAAA,EAAW,GAAGI,EAAA,CAAO,IAHpBD,MAAsB,SAAY,gBAAAG,EAACH,GAAA,CAAA,CAAkB,IAAK;AAAA,EAIrE;AACF;AAKO,SAASI,EACdP,GACAC,GACkB;AAClB,QAAM,EAAE,MAAAC,GAAM,UAAUC,EAAA,IAAsBF;AAE9C,SAAO,SAA4BG,GAA8B;AAG/D,WAFkBC,EAAeH,CAAI,IAG5BC,MAAsB,SAAY,gBAAAG,EAACH,GAAA,CAAA,CAAkB,IAAK,OAG5D,gBAAAG,EAACN,GAAA,EAAW,GAAGI,EAAA,CAAO;AAAA,EAC/B;AACF;"}