// Detail panel: General / Trackers / Peers / Content (files) / Pieces.
import { api } from './api.js';
import * as f from './format.js';
const TABS = ['general', 'trackers', 'peers', 'content', 'pieces'];
let activeTab = 'general';
let currentHash = null;
let refreshTimer = null;
let detailHeight = 300; // px, persisted across re-renders so resizing sticks
export function renderDetailShell(hash, host) {
currentHash = hash;
// Drive the container's grid track (persists across row clicks / re-renders),
// clamped so the panel always fits inside the available area.
const view = host.closest('.torrents-view');
if (view) {
detailHeight = clampDetailHeight(view, detailHeight);
view.style.setProperty('--detail-h', `${detailHeight}px`);
}
host.innerHTML = `
Transfer
${row('Status', `
${f.stateLabel(t.state)}`)}
${row('Progress', f.pct(t.progress))}
${row('Downloaded', f.bytes(t.downloaded))}
${row('Uploaded', f.bytes(t.uploaded))}
${row('Down speed', f.rate(t.dlspeed))}
${row('Up speed', f.rate(t.upspeed))}
${row('Share ratio', f.ratio(t.ratio))}
${row('ETA', f.eta(t.eta))}
${row('Availability', t.availability.toFixed(3))}
${row('Seeds', `${t.seeds} (${t.seedsTotal})`)}
${row('Peers', `${t.peers} (${t.peersTotal})`)}
${row('Down limit', t.downLimit ? f.rate(t.downLimit) : '∞')}
${row('Up limit', t.upLimit ? f.rate(t.upLimit) : '∞')}
${row('Ratio limit', t.ratioLimit > 0 ? t.ratioLimit.toFixed(2) : 'global')}
${row('Session DL / UL', `${f.bytes(t.downloadedSession)} / ${f.bytes(t.uploadedSession)}`)}
${row('Time active', f.duration(t.timeActive))}
Information
${row('Name', f.esc(t.name), true)}
${row('Total size', f.bytes(t.size))}
${row('Pieces', `${t.pieceCount} × ${f.bytes(t.pieceSize)}`)}
${row('Save path', f.esc(t.savePath), true)}
${row('Content path', f.esc(t.contentPath), true)}
${row('Category', t.category ? `
${f.esc(t.category)}` : '—')}
${row('Tags', t.tags.length ? t.tags.map((x) => `
${f.esc(x)}`).join(' ') : '—')}
${row('Added on', f.date(t.addedOn))}
${row('Completed on', f.date(t.completionOn))}
${row('Last activity', f.ago(t.lastActivity))}
${row('Hash (v1)', t.hash, true)}
${row('Privacy', t.private ? '
PRIVATE' : 'Public (DHT/PeX/LSD)')}
${row('Created by', f.esc(t.createdBy), true)}
${row('Creation date', f.date(t.creationDate))}
${row('Sequential', t.seqDl ? 'On' : 'Off')}
${row('Super seeding', t.superSeeding ? 'On' : 'Off')}
${row('Auto TMM', t.autoTMM ? 'On' : 'Off')}
${row('Force start', t.forceStart ? 'On' : 'Off')}
${t.comment ? row('Comment', f.esc(t.comment)) : ''}
`;
}
/* ---------- Trackers ---------- */
function renderTrackers(trackers) {
return `