File size: 3,506 Bytes
4fdf972
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use client";

import { useLanguage } from "@/components/LanguageContext";

const QUICKSTART_BADGES = [
  "quickstartBadgeCompat",
  "quickstartBadgeUnifiedKey",
  "quickstartBadgeModelSwitch",
  "quickstartBadgeUsage",
  "quickstartBadgeBeta",
] as const;

const CODE_LINES: { text: string; className: string }[] = [
  { text: 'import OpenAI from "openai";', className: "text-violet-300" },
  { text: "", className: "" },
  { text: "const client = new OpenAI({", className: "text-sky-300" },
  { text: '  baseURL: "https://api.hubapi.ai/v1",', className: "text-emerald-300/90" },
  { text: "  apiKey: process.env.HUBAPI_KEY", className: "text-emerald-300/90" },
  { text: "});", className: "text-sky-300" },
  { text: "", className: "" },
  { text: "const response = await client.chat.completions.create({", className: "text-sky-300" },
  { text: '  model: "anthropic/claude-sonnet",', className: "text-emerald-300/90" },
  { text: "  messages: [", className: "text-sky-300" },
  { text: "    {", className: "text-foreground/70" },
  { text: '      role: "user",', className: "text-emerald-300/90" },
  { text: '      content: "Explain this document simply."', className: "text-emerald-300/90" },
  { text: "    }", className: "text-foreground/70" },
  { text: "  ]", className: "text-sky-300" },
  { text: "});", className: "text-sky-300" },
  { text: "", className: "" },
  { text: "console.log(response.choices[0].message.content);", className: "text-amber-200/90" },
];

export function ApiQuickstartPreview() {
  const { t } = useLanguage();

  return (
    <div className="w-full max-w-3xl mx-auto">
      <div className="w-full shadow-2xl overflow-hidden border border-border dark:border-primary/30 relative z-10 bg-card/95 backdrop-blur-xl corner-bracket p-0.5">
        <div className="corner-bracket-inner" />

        <div className="flex items-center justify-between px-4 py-2.5 border-b border-primary/20 bg-primary/[0.04]">
          <div className="flex items-center gap-2">
            <div className="w-2 h-2 rounded-full bg-red-500/80" />
            <div className="w-2 h-2 rounded-full bg-yellow-500/80" />
            <div className="w-2 h-2 rounded-full bg-green-500/80" />
          </div>
          <span className="text-[10px] md:text-xs font-mono text-primary/80 uppercase tracking-widest font-bold">
            api-quickstart.ts
          </span>
        </div>

        <pre className="p-4 md:p-6 overflow-x-auto font-mono text-[11px] md:text-xs leading-relaxed bg-black/90 text-left rtl:text-left">
          <code>
            {CODE_LINES.map((line, idx) => (
              <span key={idx} className="block">
                {line.text ? (
                  <span className={line.className || "text-primary/80"}>{line.text}</span>
                ) : (
                  "\u00A0"
                )}
              </span>
            ))}
          </code>
        </pre>
      </div>

      <p className="mt-4 text-sm md:text-base text-center text-foreground/90 font-mono font-semibold">
        {t("terminalCodeHint")}
      </p>

      <div className="mt-6 flex flex-wrap items-center justify-center gap-2">
        {QUICKSTART_BADGES.map((key) => (
          <span
            key={key}
            className="inline-flex items-center rounded-full border border-primary/20 bg-primary/5 px-3 py-1 text-[10px] sm:text-[11px] font-mono font-semibold tracking-wide text-primary/90"
          >
            {t(key)}
          </span>
        ))}
      </div>
    </div>
  );
}