import { Link } from "@tanstack/react-router";
import { usePollWhile } from "~/hooks/use-poll-while";
import { buttonClass } from "./ui/Button";
import { formatDuration } from "./ui/Primitives";
import type { RepoSummary } from "~/lib/types";
const POLL_INTERVAL_MS = 4000;
type Props = {
owner: string;
name: string;
status: RepoSummary["status"];
error: string | null;
createdAt: number;
canAdmin: boolean;
};
/**
* Artifacts reports no byte-level progress for imports or forks, so this shows an indeterminate bar
* with elapsed time and refreshes until the provisioning Workflow marks the repo ready or failed.
*/
export function RepoProvisioning({ owner, name, status, error, createdAt, canAdmin }: Props) {
const pending = status === "importing" || status === "forking";
const now = usePollWhile(pending, POLL_INTERVAL_MS);
if (!pending) {
return (
<div role="alert" className="space-y-3 rounded-lg border border-red-900/70 bg-red-950/30 p-6">
<h2 className="text-lg font-semibold text-red-200">This repository could not be set up</h2>
<p className="text-sm text-red-300/80">
{error ? `Artifacts reported: ${error}.` : "Artifacts did not finish copying the repository."}
</p>
{canAdmin && (
<Link to="/$owner/$repo/settings" params={{ owner, repo: name }} className={buttonClass("danger", "sm")}>
Delete and try again
</Link>
)}
</div>
);
}