const { Diagram, DiagramNode, DiagramArrow } = window.SamsonAILabDesignSystem_8f27a2;

/* Copy is taken verbatim from the source document's sample copy (§9.2).
   Company names, quotes and metrics there are illustrative placeholders. */

const CAPABILITIES = [
  {
    id: "agents",
    label: "Agents",
    icon: "bot",
    color: "var(--color-cat-amber)",
    prose: "Write tasks in regular TypeScript and let an agent work through them for as long as it needs.",
    link: "Agents overview",
    code: [
      "// An agent loop that survives redeploys and retries its tool calls",
      'import { task } from "@samson/sdk";',
      "",
      "export const research = task({",
      '  id: "research-agent",',
      "  retry: { maxAttempts: 3, factor: 2 },",
      "  run: async ({ question }) => {",
      "    let notes = [];",
      "    while (!done(notes)) {",
      "      const step = await model.plan({ question, notes });",
      "      notes.push(await tools.run(step));",
      "    }",
      "    return summarize(notes);",
      "  },",
      "});",
    ].join("\n"),
  },
  {
    id: "media",
    label: "Media processing",
    icon: "film",
    color: "var(--color-cat-magenta)",
    prose: "Move heavy encoding off your server and stream progress back as each segment finishes.",
    link: "Media docs",
    code: [
      "// Long encodes run to completion — there is no request timeout",
      'import { task } from "@samson/sdk";',
      "",
      "export const transcode = task({",
      '  id: "transcode-upload",',
      "  machine: { preset: \"large-2x\" },",
      "  run: async ({ assetId }, { metadata }) => {",
      "    for (const segment of await split(assetId)) {",
      "      await ffmpeg(segment);",
      "      metadata.set(\"progress\", segment.index);",
      "    }",
      "  },",
      "});",
    ].join("\n"),
  },
  {
    id: "human",
    label: "Human in the loop",
    icon: "user-check",
    color: "var(--color-cat-blue)",
    prose: "Pause a run until a person approves it, then carry on from exactly where you left off.",
    link: "Waitpoint docs",
    code: [
      "// The run waits for a person, then resumes with their answer",
      'import { task, wait } from "@samson/sdk";',
      "",
      "export const publish = task({",
      '  id: "publish-with-approval",',
      "  run: async ({ draftId }) => {",
      "    const token = await wait.createToken({ timeout: \"7d\" });",
      "    await notify.reviewers(draftId, token.id);",
      "    const result = await wait.forToken(token);",
      "    if (result.ok) return cms.publish(draftId);",
      "  },",
      "});",
    ].join("\n"),
  },
  {
    id: "streaming",
    label: "Streaming",
    icon: "radio",
    color: "var(--color-cat-sun)",
    prose: "Subscribe to a run and render its status and metadata as it changes.",
    link: "Realtime docs",
    code: [
      "// Stream tokens straight into your interface as they are produced",
      'import { streams } from "@samson/sdk";',
      "",
      "export const answer = task({",
      '  id: "answer-question",',
      "  run: async ({ prompt }) => {",
      "    const out = await streams.open(\"tokens\");",
      "    for await (const token of model.stream(prompt)) {",
      "      await out.write(token);",
      "    }",
      "  },",
      "});",
    ].join("\n"),
  },
  {
    id: "python",
    label: "Run Python",
    icon: "terminal",
    color: "var(--color-cat-green)",
    prose: "Call a Python script from a TypeScript task and keep one deployment.",
    link: "Python guide",
    code: [
      "// Python runs inside the same task, with the same retries",
      'import { python } from "@samson/python";',
      "",
      "export const score = task({",
      '  id: "score-batch",',
      "  run: async ({ rows }) => {",
      '    const result = await python.runScript("./score.py", [rows]);',
      "    return JSON.parse(result.stdout);",
      "  },",
      "});",
    ].join("\n"),
  },
  {
    id: "campaigns",
    label: "Campaigns",
    icon: "megaphone",
    color: "var(--color-cat-rose)",
    prose: "Fan a campaign out to a million recipients and keep per-recipient run history.",
    link: "Batch docs",
    code: [
      "// One batch, one run per recipient, all individually retryable",
      'import { send } from "./send";',
      "",
      "export const campaign = task({",
      '  id: "send-campaign",',
      "  run: async ({ audienceId }) => {",
      "    const people = await audience.list(audienceId);",
      "    await send.batchTrigger(people.map((p) => ({ payload: p })));",
      "  },",
      "});",
    ].join("\n"),
  },
  {
    id: "browser",
    label: "Browser automation",
    icon: "globe",
    color: "var(--color-cat-blue)",
    prose: "Drive a real browser in a task and keep the trace attached to the run.",
    link: "Browser guide",
    code: [
      "// A headless browser session, attached to this run's history",
      'import { chromium } from "playwright";',
      "",
      "export const crawl = task({",
      '  id: "crawl-listing",',
      "  run: async ({ url }) => {",
      "    const browser = await chromium.launch();",
      "    const page = await browser.newPage();",
      "    await page.goto(url);",
      '    return page.textContent("main");',
      "  },",
      "});",
    ].join("\n"),
  },
];

const PATTERNS = [
  {
    title: "Autonomous agent",
    description: "Agents that use judgement to work through open-ended tasks.",
    diagram: (
      <Diagram bare direction="column" gap={10} label="Prompt, decide, call a tool, repeat">
        <DiagramNode type="action" label="Prompt" />
        <DiagramArrow direction="down" length={16} color="var(--diagram-action-border)" />
        <DiagramNode type="control" label="Decide" />
        <DiagramArrow direction="down" length={16} color="var(--diagram-control-border)" />
        <DiagramNode type="parallel" label="Tool call" />
      </Diagram>
    ),
  },
  {
    title: "Human approval",
    description: "Hold a run at a waitpoint until a person accepts or rejects it.",
    diagram: (
      <Diagram bare gap={0} label="Draft, approval gate, publish or discard">
        <DiagramNode type="action" label="Draft" />
        <DiagramArrow color="var(--diagram-action-border)" />
        <DiagramNode type="control" label="Approve?" />
        <DiagramArrow color="var(--diagram-control-border)" />
        <Diagram bare direction="column" gap={8}>
          <DiagramNode type="parallel" label="Publish" />
          <DiagramNode type="neutral" label="Discard" dimmed />
        </Diagram>
      </Diagram>
    ),
  },
  {
    title: "Fan out, fan in",
    description: "Dispatch one run per item, then collect the results in a parent run.",
    diagram: (
      <Diagram bare gap={0} label="Dispatch to parallel workers and collect">
        <DiagramNode type="router" label="Dispatch" />
        <DiagramArrow color="var(--diagram-router-border)" />
        <Diagram bare direction="column" gap={6}>
          <DiagramNode type="parallel" label="Worker" />
          <DiagramNode type="parallel" label="Worker" />
          <DiagramNode type="parallel" label="Worker" />
        </Diagram>
        <DiagramArrow color="var(--diagram-parallel-border)" />
        <DiagramNode type="neutral" label="Collect" />
      </Diagram>
    ),
  },
  {
    title: "Scheduled generation",
    description: "Run on a cron, generate assets, and keep every attempt in history.",
    diagram: (
      <Diagram bare gap={0} label="Schedule triggers generation then storage">
        <DiagramNode type="action" label="Schedule" />
        <DiagramArrow color="var(--diagram-action-border)" />
        <DiagramNode type="control" label="Generate" />
        <DiagramArrow color="var(--diagram-control-border)" />
        <DiagramNode type="neutral" label="Store" />
      </Diagram>
    ),
  },
  {
    title: "Stream to your interface",
    description: "Push tokens and metadata to the client while the run is still going.",
    diagram: (
      <Diagram bare gap={0} label="Run streams through a dispatcher to the client">
        <DiagramNode type="action" label="Run" />
        <DiagramArrow color="var(--diagram-action-border)" />
        <DiagramNode type="router" label="Stream" />
        <DiagramArrow dotted color="var(--diagram-router-border)" />
        <DiagramNode type="neutral" label="Client" />
      </Diagram>
    ),
  },
];

const STATS = [
  { icon: "timer-off", color: "var(--color-cat-blue)", title: "No timeouts", body: "Write ordinary code and let it run as long as it needs." },
  { icon: "credit-card", color: "var(--color-cat-emerald)", title: "Pay for execution", body: "You're billed while your code runs, not while it waits." },
  { icon: "server-off", color: "var(--color-cat-green)", title: "Nothing to operate", body: "Deployment and scaling are handled for you." },
];

const EXTENSIONS = [
  { title: "Webhooks", description: "Receive events from any service and trigger a task.", icon: "webhook", iconColor: "var(--color-cat-teal)" },
  { title: "Schedules", description: "Cron and dynamic schedules, per environment.", icon: "calendar-clock", iconColor: "var(--color-cat-sun)" },
  { title: "Queues", description: "Named queues with per-queue concurrency limits.", icon: "layers", iconColor: "var(--color-cat-purple)" },
  { title: "Batches", description: "Trigger up to 500 runs in a single call.", icon: "boxes", iconColor: "var(--color-cat-pink)" },
  { title: "Python", description: "Run Python scripts inside a TypeScript task.", icon: "terminal", iconColor: "var(--color-cat-green)" },
  { title: "Browsers", description: "Headless Chromium with traces attached to the run.", icon: "globe", iconColor: "var(--color-cat-blue)" },
  { title: "Alerts", description: "Route failures to Slack, email or a webhook.", icon: "bell", iconColor: "var(--color-cat-red)" },
  { title: "Regions", description: "Pin a runtime to the region your data lives in.", icon: "map-pin", iconColor: "var(--color-cat-green)" },
  { title: "Self-hosting", description: "Run the whole platform on your own infrastructure.", icon: "hard-drive", iconColor: "var(--color-cat-indigo)" },
];

const FEATURE_INDEX = [
  { heading: "Tasks", links: [{ label: "Retries and backoff" }, { label: "Idempotency keys" }, { label: "Concurrency limits" }, { label: "Machine presets" }, { label: "Task versions", external: true }, { label: "Lifecycle hooks" }] },
  { heading: "Runs", links: [{ label: "Full run history" }, { label: "Replay a run" }, { label: "Cancel and reattempt" }, { label: "Metadata and progress" }, { label: "Structured logs", external: true }, { label: "Traces and spans" }] },
  { heading: "Platform", links: [{ label: "Preview environments" }, { label: "CLI and CI deploys" }, { label: "Secrets management" }, { label: "Role-based access" }, { label: "Audit log", external: true }, { label: "SOC 2 report" }] },
];

const TESTIMONIALS = [
  { quote: "We moved our nightly data sync onto Samson AI Lab and cut the maintenance work to almost nothing. The run history alone has saved us hours of debugging.", name: "Priya Raman", role: "Staff Engineer, Northwind Analytics" },
  { quote: "Our video pipeline used to fall over on anything longer than fifteen minutes. Now the encode just runs, and we can see exactly which segment failed.", name: "Marc Oyelaran", role: "Platform Lead, Vellum Media", storyLabel: "Read the full story" },
  { quote: "Human approval steps used to mean a queue, a database table and a cron job. It is now four lines inside the task itself.", name: "Sofia Bergqvist", role: "Founding Engineer, Kestrel" },
  { quote: "We deploy from CI and the preview environment gets its own runs. Reviewing a change means reading its run history, not guessing.", name: "Dan Whitfield", role: "Engineering Manager, Ardent Labs" },
  { quote: "Billing by execution time changed the maths for us. Waiting on a model no longer costs us a server.", name: "Ada Nwosu", role: "CTO, Rivet Health" },
];

const NAV_LINKS = [
  { label: "Product", items: [{ label: "Agents", icon: "bot", color: "var(--color-cat-amber)" }, { label: "Realtime", icon: "radio", color: "var(--color-cat-sun)" }, { label: "Queues", icon: "layers", color: "var(--color-cat-purple)" }, { label: "Runs", icon: "history", color: "var(--color-cat-indigo)" }] },
  { label: "Docs" },
  { label: "Pricing" },
  { label: "Changelog" },
];

const FOOTER_COLUMNS = [
  { heading: "Docs", links: [{ label: "Quick start" }, { label: "Tasks" }, { label: "Runs" }, { label: "Deployment" }] },
  { heading: "Developers", links: [{ label: "GitHub" }, { label: "SDK reference" }, { label: "Examples" }, { label: "Status" }] },
  { heading: "Product", links: [{ label: "Agents" }, { label: "Realtime" }, { label: "Pricing" }, { label: "Self-hosting" }] },
  { heading: "Company", links: [{ label: "Blog" }, { label: "Careers" }, { label: "Security" }, { label: "Contact" }] },
];

const LOGO_ROWS = [
  ["Northwind", "Vellum Media", "Kestrel", "Ardent Labs", "Rivet Health", "Fathom"],
  ["Grayling", "Beacon", "Lumen Works", "Tidewater", "Halcyon", "Ostrom"],
];

Object.assign(window, { CAPABILITIES, PATTERNS, STATS, EXTENSIONS, FEATURE_INDEX, TESTIMONIALS, NAV_LINKS, FOOTER_COLUMNS, LOGO_ROWS });
