// Rollouts: everything you've started, live or finished. Refreshes itself while anything is running.
import { $, api, esc, dur, ago, statusPill, rewardBadge, LIVE_STATUSES, sk, emptyState, visibilityBadge } from "./util.js";
import { icon } from "./icons.js";
import { getSession } from "./session.js";
let timer = null, alive = true;
const FAILED = ["failed", "cancelled", "interrupted"];
export function unmount() { alive = false; clearTimeout(timer); }
const head = (stats = "") => `
My rollouts
Only yours, public and private. They keep going when you close the page. Everyone's public rollouts are under Community.
${stats}
`;
export async function mount(el) {
alive = true;
if (!getSession().user) {
el.innerHTML = `
${head()}
${emptyState("user", "Sign in to run rollouts",
"Pick a task, choose an agent and a model from HF Inference Providers, and watch it work in an HF Sandbox. Runs are billed to your Hugging Face account.",
``)}
${runs.length ? emptyState("filter", "Nothing in this view", "Try another filter.")
: emptyState("play", "No rollouts yet", "Open a task and run one. It shows up here with its live trajectory and reward.", `${icon("grid", 15)}Browse environments`)}