import React, { useState } from 'react'; import { useLocation } from 'react-router-dom'; interface PreviewBannerProps { token: string | null; domain: string | null; previewMode: boolean; documentationReady: boolean; onActivatePreview: () => Promise; onDeactivatePreview: () => Promise; } const PreviewBanner = ({ token, domain, previewMode, documentationReady, onActivatePreview, onDeactivatePreview, }: PreviewBannerProps): JSX.Element | null => { const [loading, setLoading] = useState(false); const location = useLocation(); if (location.pathname !== '/agent-analytics') return null; const handleActivate = async () => { setLoading(true); try { await onActivatePreview(); } finally { setLoading(false); } }; const handleDeactivate = async () => { setLoading(true); try { await onDeactivatePreview(); } finally { setLoading(false); } }; const handleViewPreview = () => { if (!domain) return; const storeUrl = domain.startsWith('http') ? domain : `https://${domain}`; const cleanDomain = domain.replace(/^https?:\/\//, ''); window.open(`${storeUrl}?recomaze_auth=test_${cleanDomain}`, '_blank'); }; const chipBase = 'inline-flex items-center px-2.5 py-0.5 text-[10px] sm:text-xs font-bold uppercase tracking-wider border'; const chipActive = `${chipBase} bg-black text-white border-black`; const chipInactive = `${chipBase} bg-gray-50 text-gray-500 border-gray-200`; const btnBase = 'inline-flex shrink-0 items-center justify-center gap-2 rounded-lg px-5 py-2.5 text-sm font-bold transition-all focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-black disabled:cursor-not-allowed disabled:opacity-50'; const primaryBtn = `${btnBase} bg-black text-white hover:bg-gray-800 disabled:bg-gray-200 disabled:text-gray-400`; const secondaryBtn = `${btnBase} border border-gray-300 bg-white text-black hover:bg-gray-50`; return (
{/* Header & Actions */}
Preview Mode: {previewMode ? 'Active' : 'Disabled'}

Store Preview Environment

Test how Recomaze integrates and behaves on your live store safely before deploying it to your customers.

{!previewMode ? ( ) : ( <> )}
{/* Warning Notice */}

Visibility Restriction

Activating Preview Mode immediately hides the widget from live store traffic. Only administrators using the preview link will see the integration. Ensure you disable preview mode to restore public access.

{/* Documentation Status */}
{documentationReady ? ( ) : ( )}
{documentationReady ? ( <>

Documentation Ready

System logic has been compiled successfully. The popup is primed to render on your storefront.

) : ( <>

Generating Documentation

If the interface is not rendering, system logic is still compiling in the background. Please wait a few moments.

)}
); }; export default PreviewBanner;