import React, { useState, useEffect } from 'react'; import { User, Mail, Building, MapPin, Shield, Save, Lock, Plus, Bell, RefreshCw, Loader2, Terminal, Zap, CheckCircle2, AlertCircle, Globe, ExternalLink, ShieldAlert, Fingerprint } from 'lucide-react'; import { CustomerProfileResponse } from '../types/index.ts'; import { callGemini } from '../services/geminiService.ts'; // Fix: Updated MOCK_PROFILE to conform to the nested CustomerProfileResponse interface const MOCK_PROFILE: CustomerProfileResponse = { customer: { firstName: 'Alex', lastName: 'Rivera', middleName: '', title: 'Mx.', companyName: 'Lumina Quantum Systems' }, contacts: { emails: [ 'a.rivera@luminaquantum.io' ], addresses: [ { addressLine1: '401 Quantum Drive', city: 'Palo Alto', region: 'CA', country: 'US', postalCode: '94304', type: 'BUSINESS' } ], phones: [ { type: 'CELL', country: '1', number: '9542312002' } ] } }; const Settings: React.FC = () => { const [activeTab, setActiveTab] = useState<'profile' | 'security' | 'notifications'>('profile'); // Security State const [isRotating, setIsRotating] = useState(false); const [rotationStep, setRotationStep] = useState(null); const [masterKey, setMasterKey] = useState('cf532cc7c81046e6...'); const [rotationLog, setRotationLog] = useState(null); // Webhook State const [webhookUri, setWebhookUri] = useState(''); const [isTestingWebhook, setIsTestingWebhook] = useState(false); const [webhookLogs, setWebhookLogs] = useState<{msg: string, type: 'info' | 'success' | 'error'}[]>([]); const [toggles, setToggles] = useState({ tx: true, iam: true, dcr: false, esg: true }); const handleSave = () => { const btn = document.getElementById('save-btn'); if (btn) { const originalText = btn.innerHTML; btn.innerText = 'Syncing...'; btn.classList.add('bg-emerald-600'); setTimeout(() => { btn.innerText = 'Saved to Node'; setTimeout(() => { btn.innerHTML = originalText; btn.classList.remove('bg-emerald-600'); }, 1500); }, 1000); } }; const handleRotateCredentials = async () => { setIsRotating(true); setRotationLog(null); const steps = [ "Invalidating legacy RSA-OAEP sessions...", "Generating high-entropy seed (quantum-resistant)...", "Performing peer-to-peer node handshake...", "Finalizing re-keying protocol..." ]; try { for (const step of steps) { setRotationStep(step); await new Promise(r => setTimeout(r, 600)); } const response = await callGemini( 'gemini-3-flash-preview', "Generate a technical 1-sentence confirmation for a successful RSA-OAEP-256 key rotation. Mention a new entropy seed and block verification. Tone: Technical." ); const newKey = 'lq_' + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); setMasterKey(newKey); // Fix: Access .text property directly setRotationLog(response.text || "Success: Network re-keyed with new master secret."); } catch (err) { setRotationLog("Key rotation complete. System re-keyed via fallback entropy."); } finally { setIsRotating(false); setRotationStep(null); } }; const handleTestWebhook = async () => { if (!webhookUri.trim()) { setWebhookLogs([{ msg: 'Error: Target URI is required for dispatch.', type: 'error' }]); return; } setIsTestingWebhook(true); setWebhookLogs(prev => [...prev, { msg: `Attempting dispatch to ${webhookUri}...`, type: 'info' }]); try { const payloadResponse = await callGemini( 'gemini-3-flash-preview', "Generate a realistic JSON webhook payload for a 'Large Institutional Transfer Detected' event. Include tx_id, amount, status: 'VERIFIED', and timestamp. Return ONLY JSON.", { responseMimeType: "application/json" } ); // Fix: Use response.text instead of manual part extraction const payload = JSON.parse(payloadResponse.text || '{}'); setWebhookLogs(prev => [...prev, { msg: `Neural Payload built: ${payload.tx_id || 'ID_NUL'}`, type: 'info' }]); // Attempt actual HTTP POST // Note: Browsers will often block this due to CORS unless the target allows it. // We handle the catch specifically for this "Failed to fetch" scenario. const response = await fetch(webhookUri, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ event: 'LUMINA_TEST_DISPATCH', timestamp: new Date().toISOString(), data: payload, note: "This is an institutional test packet from Lumina Quantum Registry." }), mode: 'cors' }); if (response.ok) { setWebhookLogs(prev => [...prev, { msg: `HTTP ${response.status}: Target acknowledged receipt.`, type: 'success' }]); } else { setWebhookLogs(prev => [...prev, { msg: `HTTP ${response.status}: Node connection established, but target returned non-200.`, type: 'error' }]); } } catch (err) { const isCors = err instanceof TypeError && err.message === "Failed to fetch"; if (isCors) { setWebhookLogs(prev => [ ...prev, { msg: `Browser Dispatch Attempted. Packet sent to network.`, type: 'success' }, { msg: `Note: Target may lack 'Access-Control-Allow-Origin' headers (CORS). Check server logs directly.`, type: 'info' } ]); } else { setWebhookLogs(prev => [...prev, { msg: `Dispatch Error: ${err instanceof Error ? err.message : 'Unknown network failure'}`, type: 'error' }]); } } finally { setIsTestingWebhook(false); } }; return (

Registry Settings

Manage your verified Data Recipient identity and system protocols.

setActiveTab('profile')} icon={User} label="Identity Profile" /> setActiveTab('security')} icon={Shield} label="Auth & Security" /> setActiveTab('notifications')} icon={Bell} label="Event Webhooks" />
{activeTab === 'profile' && (

Legal Identity

{/* Fix: Accessed nested customer properties in MOCK_PROFILE */}
{/* Fix: Accessed nested companyName property */}

Contact Registry

{/* Fix: Accessed nested contacts.emails and contacts.phones */}

Mailing Address

{/* Fix: Use addresses property from nested contacts object */} {MOCK_PROFILE.contacts.addresses.map((addr, idx) => (

{addr.type}

{addr.addressLine1}

{/* Fix: Used addr.country as per CustomerAddress type */}

{addr.city}, {addr.country} {addr.postalCode}

))}
)} {activeTab === 'security' && (
{isRotating ? : }
{isRotating && (
)}

Quantum Authentication

Secure machine-to-machine session management via rotating RSA-OAEP-256 encrypted master secrets.

Active Session Secret

{masterKey}
{rotationStep && (

{rotationStep}

)} {rotationLog && !isRotating && (
"{rotationLog}"
)}
)} {activeTab === 'notifications' && (

Event Webhook Gateway

setToggles({...toggles, tx: !toggles.tx})} /> setToggles({...toggles, iam: !toggles.iam})} /> setToggles({...toggles, dcr: !toggles.dcr})} /> setToggles({...toggles, esg: !toggles.esg})} />
setWebhookUri(e.target.value)} placeholder="e.g. https://your-endpoint.io/webhook" className="w-full bg-black border border-zinc-800 focus:border-blue-500/50 rounded-2xl pl-12 pr-5 py-4 text-zinc-200 font-mono text-xs outline-none transition-all placeholder:text-zinc-800" />
{webhookLogs.length > 0 && (
LQI Webhook Console
{webhookLogs.map((log, i) => (
[{new Date().toLocaleTimeString([], { hour12: false })}] {log.type === 'error' && } {log.msg}
))}
)}
)}
); }; const NavButton = ({ active, onClick, icon: Icon, label }: any) => ( ); const Input = ({ label, value }: any) => (
); const ToggleItem = ({ label, checked, onChange }: any) => { return (
{label}
); }; export default Settings;