import React, { useEffect, useState } from 'react'; import { Key, Plus, Trash2, Copy, Check, Webhook, Download, ShieldCheck, Zap, Terminal, } from 'lucide-react'; import { APIKey, PriorityLevel } from '../../lib/types'; import { api, getToken, triggerHaptic } from '../../lib/api'; interface EcosystemViewProps { onIngested: () => void; } export const EcosystemView: React.FC = ({ onIngested }) => { const [keys, setKeys] = useState([]); const [newKeyName, setNewKeyName] = useState(''); const [newlyCreatedKey, setNewlyCreatedKey] = useState(null); const [copiedKey, setCopiedKey] = useState(false); // Live Webhook Simulator State const [simTitle, setSimTitle] = useState('Waschmaschine im Keller ist fertig!'); const [simPriority, setSimPriority] = useState('high'); const [simStatus, setSimStatus] = useState(null); const loadKeys = async () => { const k = await api.getAPIKeys(); setKeys(k); }; useEffect(() => { loadKeys(); }, []); const handleCreateKey = async (e: React.FormEvent) => { e.preventDefault(); triggerHaptic(15); const created = await api.createAPIKey(newKeyName.trim() || 'Home Assistant'); if (created.rawKey) { setNewlyCreatedKey(created.rawKey); } setNewKeyName(''); await loadKeys(); }; const handleDeleteKey = async (id: string) => { triggerHaptic(20); await api.deleteAPIKey(id); await loadKeys(); }; const handleCopy = (text: string) => { navigator.clipboard.writeText(text); setCopiedKey(true); setTimeout(() => setCopiedKey(false), 2000); }; const handleSimulateWebhook = async () => { triggerHaptic(20); const tokenToUse = newlyCreatedKey || getToken() || ''; try { await api.testWebhookIngest(tokenToUse, simTitle, simPriority, ['smarthome', 'automation']); setSimStatus('✅ Webhook erfolgreich ausgelöst! Neue Karte liegt in deiner Inbox.'); onIngested(); setTimeout(() => setSimStatus(null), 4000); } catch (err: any) { setSimStatus(`❌ Fehler: ${err.message}`); } }; const handleFullExport = async () => { triggerHaptic(15); const data = await api.exportAll(); const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json;charset=utf-8', }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `mindsift-backup-${new Date().toISOString().slice(0, 10)}.json`; a.click(); URL.revokeObjectURL(url); }; const exampleToken = newlyCreatedKey || 'mindsift_sec_dein_api_key'; const baseUrl = window.location.origin; return (
{/* Section 1: API Keys for Smarthome & Automation */}

Webhooks & Ingestion API-Schlüssel

Verbinde Home Assistant, Zigbee2MQTT, n8n oder eigene Cronjobs direkt mit deiner MindSift Inbox.

setNewKeyName(e.target.value)} placeholder="Bezeichnung (z. B. Home Assistant, Proxmox Backup, Rauchmelder)…" className="flex-1 h-11 px-4 rounded-full bg-[#16171a] text-sm text-white placeholder-zinc-500 border border-white/[0.08] focus:outline-none focus:border-[#1d8cf8] transition-colors" />
{newlyCreatedKey && (

Neuer API-Schlüssel erstellt (bitte jetzt kopieren):

{newlyCreatedKey}
)} {/* Active Keys List */}
{keys.length === 0 ? (

Noch keine dedizierten API-Schlüssel hinterlegt.

) : ( keys.map((k) => (
{k.name} {k.keyPrefix} {k.lastUsedAt && ( Zuletzt genutzt: {new Date(k.lastUsedAt).toLocaleDateString('de-DE')} )}
)) )}
{/* Section 2: Interactive Smarthome Webhook Simulator */}

Live Smarthome Webhook-Simulator

Teste den Webhook-Endpunkt direkt hier – das Event landet sofort als Karte im Triage-Deck.

{[ { label: '🧺 Waschmaschine fertig', text: 'Waschmaschine im Keller ist fertig – Wäsche aufhängen!', prio: 'high' as PriorityLevel }, { label: '🚨 Rauchmelder Batterie', text: 'Rauchmelder Dachgeschoss meldet niedrige Batterie (12%)', prio: 'urgent' as PriorityLevel }, { label: '💧 Luftfeuchtigkeit Keller', text: 'Kellerfeuchtigkeit über 70% – Lüften oder Entfeuchter starten', prio: 'urgent' as PriorityLevel }, ].map((preset) => ( ))}
setSimTitle(e.target.value)} className="flex-1 h-11 px-4 rounded-full bg-[#16171a] text-sm text-white placeholder-zinc-500 border border-white/[0.08] focus:outline-none focus:border-[#1d8cf8] transition-colors" />
{simStatus && (

{simStatus}

)} {/* Code Example Snippets */}
cURL / Home Assistant REST Command:
{`curl -X POST "${baseUrl}/api/v1/webhooks/ingest?token=${exampleToken}" \\
  -H "Content-Type: application/json" \\
  -d '{
    "title": "Kellerfeuchtigkeit über 70%",
    "priority": "urgent",
    "tags": ["smarthome", "keller"]
  }'`}
          
{/* Section 3: Data Sovereignty & Export */}

100 % Datensouveränität & Komplett-Export

Exportiere jederzeit alle Gedanken, Aufgaben, Dokumente und geteilten Listen als portables JSON-Archiv.

); };