"use client";
import { useEffect, useState } from "react";
import { PixelButton } from "../pixel";
import { getTrackedDownloadHref, type ReleaseDownloadAsset } from "../../lib/downloads";
import { detectClientPlatform, recommendedAsset, type DetectedPlatform } from "../../lib/platform";
import styles from "./title-screen.module.css";
/** Server renders "Choose your platform"; the browser swaps in the build for this machine. */
export function PlatformCta() {
const [detected, setDetected] = useState<{ platform: DetectedPlatform; asset: ReleaseDownloadAsset | null } | null>(null);
useEffect(() => {
void detectClientPlatform().then((platform) => setDetected({ platform, asset: recommendedAsset(platform) }));
}, []);
const asset = detected?.asset ?? null;
if (!asset) {
const mac = detected?.platform.os === "macos";
return (
{mac ? "Choose your Mac build" : "Choose your platform"}
{mac ? "Apple Silicon or Intel" : "macOS · Windows · Linux"}
);
}
return (
Download for {asset.platformTitle}
{asset.label} · {asset.size} · other builds
);
}