import { useCallback, useEffect, useState } from 'react'; import { getSikshyaApi, SIKSHYA_ENDPOINTS } from '../../api'; import { __, sprintf } from '../../lib/i18n'; type NoticeAction = { label: string; url: string; target?: string; }; export type MarketingNotice = { id: string; type?: string; title?: string; message?: string; actions?: NoticeAction[]; order_count?: number; }; type NoticesPayload = { success?: boolean; data?: MarketingNotice[]; }; const BUY_PRO_ID = 'buy_pro'; export function InlineNotices() { const [notices, setNotices] = useState([]); const [loading, setLoading] = useState(true); const load = useCallback(async () => { setLoading(true); try { const res = await getSikshyaApi().get(SIKSHYA_ENDPOINTS.admin.notices); if (res?.success && Array.isArray(res.data)) { setNotices(res.data); } else { setNotices([]); } } catch { setNotices([]); } finally { setLoading(false); } }, []); useEffect(() => { void load(); }, [load]); const dismiss = useCallback( async (id: string) => { try { await getSikshyaApi().post(SIKSHYA_ENDPOINTS.admin.noticesDismiss(id), {}); } catch { // Still hide locally so the shell stays usable if REST hiccups. } setNotices((prev) => prev.filter((n) => n.id !== id)); }, [] ); if (loading || notices.length === 0) { return null; } return (
{notices.map((n) => n.id === BUY_PRO_ID ? ( void dismiss(n.id)} /> ) : ( void dismiss(n.id)} /> ) )}
); } function ReviewCard({ notice, onDismiss }: { notice: MarketingNotice; onDismiss: () => void }) { const primary = notice.actions?.[0]; const title = notice.title || ''; const message = notice.message || ''; return (
{title ?

{title}

: null} {message ? (

{message}

) : null}
{primary?.url && primary?.label ? ( {primary.label} ) : null}
); } function BuyProStrip({ notice, onDismiss }: { notice: MarketingNotice; onDismiss: () => void }) { const primary = notice.actions?.[0]; const ctaUrl = primary?.url || 'https://mantrabrain.com/plugins/sikshya-lms/pricing/?utm_source=sikshya&utm_medium=admin&utm_campaign=upgrade-gate&utm_content=buy-pro-strip'; const ctaLabel = primary?.label || __('Upgrade to Pro', 'sikshya'); const orderCount = typeof notice.order_count === 'number' ? notice.order_count : 0; return (
{__('âš¡ Limited time', 'sikshya')}

{__('🚀 Upgrade to Sikshya Pro — up to 50% off!', 'sikshya')}

{sprintf( __( 'You’ve recorded %1$d order(s)! Get up to 50%% off on Sikshya Pro. Unlock premium payment tools, advanced modules, automation, and priority support.', 'sikshya' ), orderCount )}

{__( '🎉 Special Offer: Save up to 50% on your Pro upgrade with premium features and priority support!', 'sikshya' )}
{sprintf(__('⚡ Save up to 50%% — %s', 'sikshya'), ctaLabel)}
); }