// aerOS Superadmin — Platform Settings: shared AI (Anthropic) API key. // One key, used by every tenant whose plan includes the AI feature. function SaSettings({ t }) { const { useState, useEffect } = React; const toast = useToast(); const [data, setData] = useState({ anthropic_api_key_set: false, anthropic_api_key_masked: null, anthropic_model: '', ai_plans: [] }); const [key, setKey] = useState(''); const [model, setModel] = useState(''); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [testing, setTesting] = useState(false); const [result, setResult] = useState(null); // {ok, message} // SMTP const [smtp, setSmtp] = useState({ host: '', port: '587', user: '', password: '', from: '', tls: true }); const [smtpTo, setSmtpTo] = useState(''); const [smtpTesting, setSmtpTesting] = useState(false); const [smtpResult, setSmtpResult] = useState(null); const sset = (k, v) => setSmtp(s => ({ ...s, [k]: v })); const load = async () => { setLoading(true); try { const d = await window.SA_API.getSettings(); setData(d); setModel(d.anthropic_model || ''); setSmtp({ host: d.smtp_host || '', port: d.smtp_port || '587', user: d.smtp_user || '', password: '', from: d.smtp_from || '', tls: d.smtp_tls !== false }); } catch (e) {} setLoading(false); }; useEffect(() => { load(); }, []); const save = async () => { setSaving(true); try { await window.SA_API.setSettings({ anthropic_api_key: key || null, anthropic_model: model || null, smtp_host: smtp.host, smtp_port: String(smtp.port || ''), smtp_user: smtp.user, smtp_password: smtp.password || null, smtp_from: smtp.from, smtp_tls: !!smtp.tls, }); setKey(''); setSmtp(s => ({ ...s, password: '' })); await load(); toast.ok('Ayarlar kaydedildi', 'Platform ayarları güncellendi'); } catch (e) { toast.error(e.message || 'Hata'); } setSaving(false); }; const testSmtp = async () => { setSmtpTesting(true); setSmtpResult(null); try { setSmtpResult(await window.SA_API.testSmtp(smtpTo || null)); } catch (e) { setSmtpResult({ ok: false, message: e.message || 'Hata' }); } setSmtpTesting(false); }; const test = async () => { setTesting(true); setResult(null); try { const r = await window.SA_API.testApiKey(key || null, model || null); setResult(r); } catch (e) { setResult({ ok: false, message: e.message || 'Hata' }); } setTesting(false); }; const placeholder = data.anthropic_api_key_set ? (data.anthropic_api_key_masked || 'Kayıtlı anahtar var') : 'sk-ant-...'; return (