import { ApiErrorPanel } from './shared/ApiErrorPanel'; import { ButtonPrimary } from './shared/buttons'; import { PREMIUM_LOCK_CARD_CLASS } from './PremiumGatedSurface'; import { TopRightToast, useTopRightToast } from './shared/TopRightToast'; import { getErrorSummary } from '../api'; import { __, sprintf } from '../lib/i18n'; export function AddonEnablePanel(props: { title: string; description: string; canEnable: boolean; enableLabel?: string; enableBusy?: boolean; onEnable: () => Promise; upgradeUrl?: string; error?: unknown; /** When inside the gated surface, matches the plan-gate hero design. */ variant?: 'default' | 'premium'; }) { const { title, description, canEnable, enableLabel, enableBusy, onEnable, upgradeUrl, error, variant = 'default' } = props; const toast = useTopRightToast(3200); const onEnableClick = async () => { toast.clear(); try { await onEnable(); const base = title.replace(/\s+is\s+not\s+enabled\s*$/i, '').trim(); toast.success( __('Enabled', 'sikshya'), base ? sprintf(__('%s enabled.', 'sikshya'), base) : __('Add-on enabled.', 'sikshya') ); } catch (e) { toast.error(__('Enable failed', 'sikshya'), getErrorSummary(e)); } }; const isPremium = variant === 'premium'; if (!isPremium) { return (
{title}
{description}
{error ? (
void 0} />
) : null}
{canEnable ? ( {enableBusy ? __('Enabling…', 'sikshya') : enableLabel || __('Enable add-on', 'sikshya')} ) : upgradeUrl ? ( {__('Upgrade to unlock', 'sikshya')} ) : null}
); } // PREMIUM variant — hero + body + CTA, matching PlanUpgradeOverlay style. return (
{/* Hero — purple-led gradient */}
{__('Add-on', 'sikshya')}

{title}

{description}

{error ? (
void 0} />
) : null} {/* Action band */}
{canEnable ? ( ) : upgradeUrl ? ( {__('View plans & upgrade', 'sikshya')} ) : null}

{canEnable ? __('Enable in one click. Activates the feature immediately for your site.', 'sikshya') : upgradeUrl ? __('Upgrade to the right tier, then return here to enable.', 'sikshya') : __('Contact support if you need help with your license.', 'sikshya')}

); }