'use client'; import { useState } from 'react'; import { Bot, Eye, EyeOff, Loader2, CheckCircle2, XCircle, Plug, Building2 } from 'lucide-react'; import { cn } from '@/lib/utils'; interface CloseBotCardProps { settings: Record; onSave: (updates: Record) => Promise; connected: boolean | null; onTestConnection: () => Promise; testing: boolean; agencyName?: string; sourcesCount?: number; } function maskApiKey(val: string): string { if (!val || val.length < 10) return val ? '••••••••' : ''; const prefix = val.slice(0, 3); const suffix = val.slice(-4); return `${prefix}••••••••${suffix}`; } export default function CloseBotCard({ settings, onSave, connected, onTestConnection, testing, agencyName, sourcesCount }: CloseBotCardProps) { const [apiKey, setApiKey] = useState(''); const [webhookSourceId, setWebhookSourceId] = useState(''); const [showKey, setShowKey] = useState(false); const [saving, setSaving] = useState(false); const [editing, setEditing] = useState(false); const envKey = settings.closebot_api_key || ''; const envSourceId = settings.closebot_webhook_source_id || ''; async function handleSave() { setSaving(true); try { const updates: Record = {}; if (apiKey) updates.closebot_api_key = apiKey; if (webhookSourceId) updates.closebot_webhook_source_id = webhookSourceId; await onSave(updates); setEditing(false); setApiKey(''); setWebhookSourceId(''); } finally { setSaving(false); } } return (
{/* Header */}

CloseBot Connection

AI chatbot API credentials

{/* Connection status */}
{connected === null ? ( Not tested ) : connected ? ( <>
Connected ) : ( <>
Disconnected )}
{/* Agency Info — shown when connected */} {connected && (agencyName || sourcesCount !== undefined) && (
{agencyName && (

Agency

{agencyName}

)} {sourcesCount !== undefined && (

Active Sources

{sourcesCount} connected

)}
)} {/* Fields */}
{/* API Key */}
{editing ? (
setApiKey(e.target.value)} placeholder="cb_xxxxxxxxxxxxxxxxxxxxxxxx" className="w-full rounded-lg border border-slate-700/50 bg-slate-800/50 px-3 py-2 pr-10 text-sm text-slate-200 placeholder-slate-600 outline-none transition-colors focus:border-cyan-500/50 focus:ring-1 focus:ring-cyan-500/20 font-mono" />
) : (
{envKey ? maskApiKey(envKey) : Not configured}
)}
{/* Webhook Source ID */}
{editing ? ( setWebhookSourceId(e.target.value)} placeholder="Source ID from CloseBot webhook settings" className="w-full rounded-lg border border-slate-700/50 bg-slate-800/50 px-3 py-2 text-sm text-slate-200 placeholder-slate-600 outline-none transition-colors focus:border-cyan-500/50 focus:ring-1 focus:ring-cyan-500/20 font-mono" /> ) : (
{envSourceId || Not configured}
)}
{/* Actions */}
{editing ? (
) : ( )}
); }