import { api } from "@wails/go/models";
import { useState } from "react";
import { cn } from "@src/utils";
import { Tooltip } from "react-tooltip";
export default function Offer({
offer: { Offer: offer, Score: score, Reasons: reasons, Latency: latency },
}: {
offer: api.ScoredOffer;
}) {
const copy = (text: string) => navigator.clipboard.writeText(text);
const [showDetails, setShowDetails] = useState(false);
const mb_to_gb = (mb: number) => Math.round(mb / 1024);
return (
*]:px-2 flex-col relative bg-zinc-700/90 rounded max-w-md overflow-hidden":
true,
"h-24": !showDetails,
"min-h-24 max-h-48": showDetails,
})}
>
{score >= 10 ? Math.round(score) : score.toFixed(1)}
{offer.num_gpus}x {offer.gpu_name}{" "}
{mb_to_gb(offer.gpu_ram)} GB
{latency ?? "?"}
ms
${offer.search.totalHour.toFixed(2)}/hr
mem{" "}
{mb_to_gb(offer.cpu_ram)}/{mb_to_gb(offer.cpu_ram / offer.gpu_frac)}GB
dlperf{" "}
{offer.dlperf.toFixed(0)}
{Math.round(offer.duration / 60 / 60 / 24)} days
{offer.verification}
setShowDetails(!showDetails)}
className={cn({
"px-0 w-full bg-zinc-900/70 border-t cursor-pointer border-zinc-600/80 text-center":
true,
"select-none h-3 leading-[0.2rem] text-zinc-100 absolute bottom-0":
!showDetails,
"h-40 overflow-y-auto text-sm": showDetails,
})}
>
{showDetails ? (
<>
{reasons
.sort((a, _) => (a.IsMultiplier ? 1 : -1))
.map((reason, i) => (
{reason.IsMultiplier ? (
x{reason.Offset.toFixed(2)}
) : (
{reason.Offset > 0 ? "+" : null}
{reason.Offset}
)}
{reason.Reason}
))}
>
) : (
"..."
)}
);
}