import { useState } from 'react' import { Check, ChevronDown, Copy, Pencil, Plus, Trash2 } from 'lucide-react' import clsx from 'clsx' import { maskSecret } from '../../utils/maskSecret' function fallbackCopyText(text) { const textArea = document.createElement('textarea') textArea.value = text textArea.setAttribute('readonly', '') textArea.style.position = 'fixed' textArea.style.top = '-9999px' textArea.style.left = '-9999px' document.body.appendChild(textArea) textArea.focus() textArea.select() let copied = false try { copied = document.execCommand('copy') } finally { document.body.removeChild(textArea) } if (!copied) { throw new Error('copy failed') } } export default function ApiKeysPanel({ t, config, keysExpanded, setKeysExpanded, onAddKey, onEditKey, copiedKey, setCopiedKey, onDeleteKey, }) { const [failedKey, setFailedKey] = useState(null) const apiKeys = Array.isArray(config?.api_keys) && config.api_keys.length > 0 ? config.api_keys : (config?.keys || []).map(key => ({ key, name: '', remark: '' })) const handleCopyKey = async (key) => { try { if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(key) } else { fallbackCopyText(key) } setCopiedKey(key) setFailedKey(null) setTimeout(() => setCopiedKey(null), 2000) } catch { try { fallbackCopyText(key) setCopiedKey(key) setFailedKey(null) setTimeout(() => setCopiedKey(null), 2000) } catch { setFailedKey(key) setTimeout(() => setFailedKey(null), 2500) } } } return (
{t('accountManager.apiKeysDesc')} ({apiKeys.length || 0})