"use client" import { useState, useCallback } from "react" import { Card, CardHeader, CardTitle, CardDescription, CardContent, } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Progress } from "@/components/ui/progress" import { Badge } from "@/components/ui/badge" import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell, } from "@/components/ui/table" import { Tooltip, TooltipTrigger, TooltipContent, } from "@/components/ui/tooltip" import { Separator } from "@/components/ui/separator" import { Plus, Copy, Trash2, Eye, EyeOff, Zap, Webhook, Check, } from "lucide-react" const initialKeys = [ { id: "1", name: "Production", key: "otr_live_a3f8k29d...x7m1", fullKey: "otr_live_a3f8k29d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9tx7m1", created: "Jan 14, 2026", lastUsed: "2 hours ago", status: "active" as const, }, { id: "2", name: "Staging", key: "otr_test_b7c2m41n...p9q3", fullKey: "otr_test_b7c2m41n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0dp9q3", created: "Feb 3, 2026", lastUsed: "5 days ago", status: "active" as const, }, { id: "3", name: "CI/CD Pipeline", key: "otr_test_x9y1z83a...k4l6", fullKey: "otr_test_x9y1z83a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7qk4l6", created: "Feb 10, 2026", lastUsed: "12 hours ago", status: "active" as const, }, ] const WEBHOOK_SNIPPET = `curl -X POST https://api.officetranslator.com/v1/translate \\ -H "Authorization: Bearer otr_live_a3f8..." \\ -H "Content-Type: multipart/form-data" \\ -F "file=@report.xlsx" \\ -F "source=en" \\ -F "target=fr" \\ -F "callback_url=https://your-app.com/webhook/done"` export function ApiAutomationCard() { const [keys, setKeys] = useState(initialKeys) const [revealedKeys, setRevealedKeys] = useState>(new Set()) const [copiedId, setCopiedId] = useState(null) const [copiedSnippet, setCopiedSnippet] = useState(false) const usedCalls = 150 const totalCalls = 500 const percentUsed = (usedCalls / totalCalls) * 100 const toggleReveal = useCallback((id: string) => { setRevealedKeys((prev) => { const next = new Set(prev) if (next.has(id)) { next.delete(id) } else { next.add(id) } return next }) }, []) const copyKey = useCallback((id: string, fullKey: string) => { navigator.clipboard.writeText(fullKey) setCopiedId(id) setTimeout(() => setCopiedId(null), 2000) }, []) const copySnippet = useCallback(() => { navigator.clipboard.writeText(WEBHOOK_SNIPPET) setCopiedSnippet(true) setTimeout(() => setCopiedSnippet(false), 2000) }, []) const revokeKey = useCallback((id: string) => { setKeys((prev) => prev.filter((k) => k.id !== id)) }, []) const generateKey = useCallback(() => { const newKey = { id: String(Date.now()), name: `Key ${keys.length + 1}`, key: "otr_live_new_key...xxxx", fullKey: "otr_live_new_key_generated_" + Date.now(), created: "Just now", lastUsed: "Never", status: "active" as const, } setKeys((prev) => [...prev, newKey]) }, [keys.length]) return (
API & Automation Manage your API keys, monitor usage, and configure webhooks
{/* Quota Section */}
Monthly Quota {usedCalls} {" / "}{totalCalls} API calls
{Math.round(percentUsed)}% used

Resets on March 1, 2026. Need more?{" "}

{/* API Keys Table */}

Active API Keys

Name Key Created Last Used Actions {keys.map((apiKey) => ( {apiKey.name} {revealedKeys.has(apiKey.id) ? apiKey.fullKey.substring(0, 32) + "..." : apiKey.key} {apiKey.created} {apiKey.lastUsed}
{revealedKeys.has(apiKey.id) ? "Hide" : "Reveal"} {copiedId === apiKey.id ? "Copied!" : "Copy"} Revoke
))} {keys.length === 0 && ( No active API keys. Generate one to get started. )}
{/* Webhook Code Snippet */}

Webhook Integration

Pass a callback_url parameter to receive a POST request when your translation is complete.

              {WEBHOOK_SNIPPET}
            
) }