import React, { useState } from "react"; import { __ } from "@wordpress/i18n"; /** * A calm, dismissible "Upgrade to Pro" card for the free admin sidebar. * * Pure presentational: it links to the B3 Software store URL supplied by * the localized payload and never blocks any free workflow. It honors the * no-nag-popups promise — once dismissed (persisted in localStorage) it collapses * to a single one-line link rather than disappearing entirely. * * This component is intentionally free-side only (it lives outside the * `extension/` tree and imports nothing premium). It is rendered by the free * admin App, which is not mounted in the Pro build, so Pro users never see it. */ const DISMISS_KEY = "b3wvs_pro_upgrade_card_dismissed_v1"; const PRO_FEATURES: readonly string[] = [ __("Shop & archive page swatches", "b3-swatches"), __("AJAX add to cart + cart notices", "b3-swatches"), __("Variation share URLs & social sharing", "b3-swatches"), __("Custom typography & Google Fonts", "b3-swatches"), ]; export interface ProUpgradeCardProps { /** Canonical B3 Software store URL from the localized payload. */ storeUrl?: string; } function readDismissed(): boolean { try { return window.localStorage.getItem(DISMISS_KEY) === "1"; } catch { return false; } } export function ProUpgradeCard({ storeUrl, }: ProUpgradeCardProps): React.ReactElement { const [dismissed, setDismissed] = useState(readDismissed); const href = storeUrl?.trim() || ""; if (!href) { return <>; } const handleDismiss = (): void => { try { window.localStorage.setItem(DISMISS_KEY, "1"); } catch { // Storage may be unavailable (private mode); dismiss for this session only. } setDismissed(true); }; if (dismissed) { return ( {__("Upgrade to Pro", "b3-swatches")} ); } return (

{__("Upgrade to Pro", "b3-swatches")}

{__("You're on the free version. Pro adds:", "b3-swatches")}

{__("View Pro Plans", "b3-swatches")}
); }