"use client";
import * as React from "react";
import Link from "next/link";
import type { FetchRequestInput, FetchResponseBody } from "@fetcha/core/client";
import { ArrowUpRight, Download, Loader2, MonitorSmartphone, PlayCircle, ShieldAlert } from "lucide-react";
import type { PlaygroundError } from "@/actions/playground";
import { Alert } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { CodeBlock } from "@/components/ui/code-block";
import { CopyButton } from "@/components/ui/copy-button";
import { EmptyState } from "@/components/ui/empty-state";
import { Skeleton } from "@/components/ui/skeleton";
import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import type { CodegenLang } from "@/lib/codegen";
import { formatBytes, formatMs } from "@/lib/format";
import { cn } from "@/lib/utils";
import { CodePanel } from "./code-panel";
import { TimingBars } from "./timing-bars";
import { isHtmlContentType, isJsonContentType, statusVariant, stripHtml, truncateForDisplay, type NetworkClass, type PlaygroundKey } from "./types";
export type ResultPhase = "idle" | "running" | "success" | "error";
export interface ResultsPanelProps {
phase: ResultPhase;
result: FetchResponseBody | null;
error: PlaygroundError | null;
elapsedMs: number;
request: FetchRequestInput;
requestNetwork: NetworkClass;
keys: PlaygroundKey[];
baseUrl: string;
codeLang: CodegenLang;
onCodeLangChange: (l: CodegenLang) => void;
keyId: string;
onKeyChange: (id: string) => void;
onSaveCurl: () => void;
}
export function ResultsPanel(p: ResultsPanelProps) {
const code = ;
if (p.phase === "idle") {
return (
{code}
);
}
if (p.phase === "running") {
return (
Routing your request…
{p.requestNetwork === "auto" ? "Auto mode picks the best network for this domain, then retries with a new IP or another network if the target blocks." : `Using the ${p.requestNetwork} network.`}
The target answered with HTTP {r.status} on every route Fetcha tried ({meta.attempts} attempt{meta.attempts === 1 ? "" : "s"}). Try browser rendering, a residential network, a different country or a session.
Turn on Debug in the request options to see each routing attempt.
)}
How routing works
In auto mode Fetcha scores every available route for this domain — historical success (35%), cost (20%), latency (15%), network health (15%), geography (10%) and session stability (5%) — starts with the cheapest network likely to succeed and escalates to premium networks when the target blocks or times out. Each retry uses a new IP. When an attempt is blocked by a JavaScript challenge and browser fallback is on, the next attempt is rendered in the managed browser. Requesting a specific network pins the first attempt to that class.