/* "Your networks" on the title screen: drawn from the index alone, so it stays instant however big the saves are. */
function slotAgo(t){const m=Math.max(0,Math.round((Date.now()-t)/60000));
return m<1?tr('slots.just_now'):m<60?trn('notifications.n_min_ago',m):m<1440?trn('slots.n_h_ago',Math.round(m/60)):trn('slots.n_day_ago',Math.round(m/1440));}
const slotIcon=e=>e.broken?'🩹':e.mode==='scenario'?'🏆':e.mode==='sandbox'?'🏖️':(PRESETS[e.preset]||PRESETS.oncall).i;
// The network to continue: the most recent one that is not open in another window (or damaged).
function slotTop(list){return slotByAt(list).find(e=>!e.broken&&!slotBusy(e.id))||null;}
function slotLine(e){if(e.broken)return tr('slots.damaged_export_or_delete');
const bits=[e.asn?'AS'+e.asn:'',e.name||e.gz?dateStr(e.day):''];if(e.mode==='scenario'&&e.scn)bits.push(esc(e.scn));else if(e.tier)bits.push(e.tier);
return bits.filter(Boolean).join(' · ');}
function slotRow(e,top){const busy=slotBusy(e.id),nm=esc(e.name||tr('common.unnamed_network'));
const tag=busy?`${tr('slots.open_in_another_window')}`:top?`▶ ${tr('slots.continue')}`:'';
return `
`;}
function slotListHtml(){const list=slotByAt(slotIdx()),top=slotTop(list);
return list.map(e=>slotRow(e,e===top)).join('');}
function slotsHtml(){const list=slotIdx(true);if(!list.length)return '';
SLOT.html=slotListHtml();return `
${SLOT.html}
`;}
// Another window saved, opened or closed a network: the list follows (only when it is on screen and changed).
function slotRefresh(){const el=$('slotList');if(!el||UI.started)return;const h=slotListHtml();if(h!==SLOT.html){SLOT.html=h;el.innerHTML=h;}}
function slotMenuHtml(id){const e=slotIdx().find(x=>x.id===id);if(!e)return '';const nm=esc(e.name||tr('common.unnamed_network'));
return `
`);}
// Shown in the window that stepped aside: calm, and nothing here writes.
function slotLostModal(id,name,why){const nm=esc(name||tr('common.unnamed_network'));
openModal(`
`);}
const slotOthers=()=>slotIdx().filter(e=>e.id!==UI.slot);
// Out of room: which other networks take space, with export and delete right there.
function slotSpaceHtml(){const l=slotOthers().sort((a,b)=>b.size-a.size);
return `