import type { IconSvgElement } from "@hugeicons/react"; import { ArrowLeft01Icon, ArrowRight01Icon, BotIcon, CheckmarkCircle02Icon, Copy01Icon, Key01Icon, Link01Icon, SecurityLockIcon, UserMultiple02Icon, } from "@hugeicons/core-free-icons"; import type { ReactNode } from "react"; import { Icon } from "@/components/icon"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import type { FieldValidationResult, SetupFormValues } from "@/lib/setup-types"; import { cn } from "@/lib/utils"; export const SETUP_STEP_IDS = [ "botToken", "secretKey", "oauth", "redirectUri", "owners", "emeraldApi", ] as const; export type SetupStepId = (typeof SETUP_STEP_IDS)[number]; export const SETUP_STEPS: { id: SetupStepId; title: string; subtitle: string; icon: IconSvgElement; }[] = [ { id: "botToken", title: "Bot token", subtitle: "Connect your Discord bot", icon: BotIcon, }, { id: "secretKey", title: "Session secret", subtitle: "Secure dashboard logins", icon: SecurityLockIcon, }, { id: "oauth", title: "Discord OAuth", subtitle: "Sign in with Discord", icon: Key01Icon, }, { id: "redirectUri", title: "Redirect URL", subtitle: "OAuth callback address", icon: Link01Icon, }, { id: "owners", title: "Dashboard owners", subtitle: "Who can access this panel", icon: UserMultiple02Icon, }, { id: "emeraldApi", title: "Emerald API", subtitle: "One-click addons", icon: Key01Icon, }, ]; function validationKeyForStep(id: SetupStepId): string { if (id === "oauth") return "oauth"; if (id === "owners") return "owners"; return id; } export function SetupWizardShell({ brandingTitle, faviconUrl, faviconVersion, hasFavicon, children, }: { brandingTitle: string; faviconUrl?: string | null; faviconVersion?: number; hasFavicon: boolean; children: ReactNode; }) { return (
{hasFavicon && faviconUrl ? ( ) : (
)}

First-time setup

{brandingTitle}

{children}
); } export function SetupProgress({ currentIndex, validation, }: { currentIndex: number; validation: Record; }) { const progress = ((currentIndex + 1) / SETUP_STEPS.length) * 100; return (
Step {currentIndex + 1} of {SETUP_STEPS.length} {Math.round(progress)}%

Each step can be tested with Discord before you continue. You can move back anytime to change a value.

); } export function SetupStepCard({ step, children, footer, }: { step: (typeof SETUP_STEPS)[number]; children: ReactNode; footer?: ReactNode; }) { return (

{step.title}

{step.subtitle}

{step.title}

{step.subtitle}

{children}
{footer ? (
{footer}
) : null}
); } export function ValidationBanner({ result, }: { result?: FieldValidationResult; }) { if (!result) return null; if (result.ok) { return ( {result.bot ? (

Connected as @{result.bot.username} {result.applicationId ? ( {" "} · App ID {result.applicationId} ) : null}

) : null} {result.users?.length ? (
    {result.users.map((u) => (
  • {u.globalName || u.username} {u.id}
  • ))}
) : null} {!result.bot && !result.users?.length ? (

{result.warning || "Verified successfully."}

) : null}
); } return ( {result.error} ); } export function BotTokenStep({ values, setValues, validation, validating, onValidate, }: { values: SetupFormValues; setValues: (v: SetupFormValues) => void; validation: Record; validating: boolean; onValidate: () => void; }) { return (

Open the{" "} Discord Developer Portal , select your application, go to Bot, and reset or copy the token.

setValues({ ...values, botToken: e.target.value })} placeholder="MTI…" className="h-11 font-mono text-sm" />
); } export function SecretKeyStep({ values, setValues, validation, validating, onValidate, onGenerate, }: { values: SetupFormValues; setValues: (v: SetupFormValues) => void; validation: Record; validating: boolean; onValidate: () => void; onGenerate: () => void; }) { return (

This random string signs your login cookies. Store it like a password — do not commit it to public repos.

setValues({ ...values, secretKey: e.target.value })} className="h-11 font-mono text-sm" />
); } export function OAuthStep({ values, setValues, validation, validating, onValidate, }: { values: SetupFormValues; setValues: (v: SetupFormValues) => void; validation: Record; validating: boolean; onValidate: () => void; }) { return (

Use the same application as your bot. Under OAuth2, copy the Client ID and Client Secret.

setValues({ ...values, clientId: e.target.value })} className="h-11 font-mono text-sm" />
setValues({ ...values, clientSecret: e.target.value }) } className="h-11 font-mono text-sm" />
); } export function RedirectStep({ values, setValues, validation, }: { values: SetupFormValues; setValues: (v: SetupFormValues) => void; validation: Record; }) { async function copyUri() { if (!values.redirectUri) return; try { await navigator.clipboard.writeText(values.redirectUri); } catch { /* ignore */ } } return (

Add this exact URL under OAuth2 → Redirects in the Developer Portal. It must match character-for-character.

setValues({ ...values, redirectUri: e.target.value }) } className="h-11 flex-1 font-mono text-xs" />
{validation.redirectUri && !validation.redirectUri.ok ? ( ) : ( We pre-filled this from your current dashboard URL. If you access the panel from a different domain later, update this and add the new URL in Discord too. )}
); } export function OwnersStep({ values, setValues, validation, validating, onValidate, }: { values: SetupFormValues; setValues: (v: SetupFormValues) => void; validation: Record; validating: boolean; onValidate: () => void; }) { return (

Enable Developer Mode in Discord (Settings → Advanced), then right-click your profile and Copy User ID. Add one ID per line.