import { useState } from 'react'; import { useLicenseStore } from '../store/licenseStore'; import { Key, Check, X, Loader2, Shield, Clock, AlertTriangle } from 'lucide-react'; export default function LicenseDialog() { const { status, showDialog, setShowDialog, activateLicense } = useLicenseStore(); const [key, setKey] = useState(''); const [error, setError] = useState(null); const [activating, setActivating] = useState(false); const [confirmedEmail, setConfirmedEmail] = useState(null); const [verifying, setVerifying] = useState(false); const handleActivate = async () => { if (!key.trim()) return; setError(null); // If we already verified and the user confirmed, complete activation if (confirmedEmail) { setActivating(true); const ok = await activateLicense(key.trim()); if (!ok) { setError('Invalid license key. Check it was entered correctly.'); } setActivating(false); return; } // Step 1: Verify the key (don't cache yet) to get the email setVerifying(true); try { const payload = await window.electronAPI?.verifyLicense(key.trim()); if (payload?.customer_email) { setConfirmedEmail(payload.customer_email); } else { setError('Invalid license key. Check it was entered correctly.'); } } catch { setError('Invalid license key. Check it was entered correctly.'); } setVerifying(false); }; const handleDeny = () => { setConfirmedEmail(null); setKey(''); setError(null); }; const formatDate = (ts: number) => { const d = new Date(ts * 1000); return d.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }); }; if (!status) return null; if (status.tag === 'Licensed') { return (
{status.license.tier === 'business' ? 'Business' : 'Pro'} — {status.license.customer_email} expires {formatDate(status.license.expires_at)}
); } if (status.tag === 'Trial') { return ( <>
{showDialog && ( { setShowDialog(false); handleDeny(); }} onActivate={handleActivate} onDeny={handleDeny} keyValue={key} setKeyValue={setKey} error={error} activating={activating} verifying={verifying} confirmedEmail={confirmedEmail} trialEnding={status.days_remaining <= 3} /> )} ); } // Expired — show banner + activation dialog (both dismissible) return ( <> setShowDialog(true)} /> {showDialog && ( { setShowDialog(false); handleDeny(); }} onActivate={handleActivate} onDeny={handleDeny} keyValue={key} setKeyValue={setKey} error={error} activating={activating} verifying={verifying} confirmedEmail={confirmedEmail} expired /> )} ); } /** Persistent top banner shown when trial expired — still allows export and loading */ function ExpiredBanner({ onActivate }: { onActivate: () => void }) { return (
Trial expired — export and project loading still work.   to restore editing.
); } function LicenseActivateDialog({ onClose, onActivate, onDeny, keyValue, setKeyValue, error, activating, verifying, confirmedEmail, trialEnding, expired, }: { onClose: () => void; onActivate: () => void; onDeny: () => void; keyValue: string; setKeyValue: (v: string) => void; error: string | null; activating: boolean; verifying: boolean; confirmedEmail: string | null; trialEnding?: boolean; expired?: boolean; }) { const isProcessing = activating || verifying; if (confirmedEmail) { return (
e.stopPropagation()} >

Confirm License

This license key is registered to:

{confirmedEmail}

License keys are tied to your email. Sharing this key may result in deactivation.

); } return (
e.stopPropagation()} >

{expired ? 'Trial Expired' : 'Activate TalkEdit'}

{expired && (

Your 30-day trial has ended.

You can still export videos and load projects. Enter a license key to restore editing, AI tools, and all other features.

)} {trialEnding && !expired && (

Your trial ends soon. Activate now to keep using all features.

)} {!expired && !trialEnding && (

Enter your license key to activate TalkEdit Pro or Business. You received this key by email after purchase.

)}