/* Express lightpaths (#58): the panel of one, the section on a dark fiber's panel (what rides it, where it chains on) and the Express tab of the link window (70-link-modal.js). The rules are in 80-simulation/65-express.js. */ const xpSpanName=s=>`${CITY[s.a].name} ⇄ ${CITY[s.b].name}`; // Why an express is dark today, fiber by fiber. function xpDarkWhy(l){const sp=xpSpans(l);if(!sp)return [tr('express.dark_gone')];const d=S.day,out=[]; for(const s of sp){const n=xpSpanName(s);if(linkCut(s))out.push(tr('express.dark_cut',{span:n}));else if(s.ready>d)out.push(trn('express.dark_building',s.ready-d,{span:n}));else if(s.eqDown>d)out.push(tr('express.dark_system',{span:n}));} if(!out.length)out.push(tr('express.dark_reach'));return out;} // One fiber of a path: whose it is, how long, the slots left for express channels. const xpSpanMeta=s=>`${s.own?tr('common.own_dark_fiber'):tr('common.leased_iru')} · ${Math.round(s.km).toLocaleString()} km · ${tr('express.free_slots',{n:Math.max(0,xpFree(s)),max:chMax(s)})}`; // An optic's settings over a run, as the fiber panel lists them. const xpModes=(o,run)=>OPT[o].modes.map(([g,r])=>tr('link_panels.g_to_km_km',{g:fmtG(g),km:r.toLocaleString()})).join(' · ')+` · ${xpOptG(o,run)?tr('express.runs_at',{g:fmtG(xpOptG(o,run))}):tr('express.out_of_reach')}`; function xpPanel(l){const sp=xpSpans(l),load=R.load[l.id]||0,cap=capOf(l),u=cap?load/cap:0,down=linkDown(l),A=CITY[l.a].name,B=CITY[l.b].name,run=sp?xpRunKm(sp):0,ch=l.ch||[]; let h=`
${tr('express.eyebrow',{km:Math.round(l.km).toLocaleString()})}

${A} ⇄ ${B}

`; if(down)h+=`

${tr('common.dark_6bf5')}

${xpDarkWhy(l).map(t=>`

${t}

`).join('')}
`; h+=`

${tr('common.capacity')}

${trn('express.n_channels',ch.length)}${fmtG(load)} / ${fmtG(cap)}
${tr('common.latency')}${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}
${tr('express.optical_run')}${run.toLocaleString()} km

${tr('express.passes',{via:esc(xpVia(l))})}

`; if(sp)h+=`

${tr('express.its_fibers')}

${sp.map(s=>`
${xpSpanName(s)} ${linkCut(s)?''+tr('common.cut')+'':''}
${xpSpanMeta(s)}
${btn(tr('common.open'),'selLink',{id:s.id},'ghost sm')}
`).join('')}

${tr('express.slot_note')}

`; if(sp){h+=`

${tr('common.optics')}

`; for(const k of Object.keys(OPT)){const O=OPT[k],n=ch.filter(x=>x===k).length;if(!n&&!techOk('opt',k,O.lvl))continue;const why=xpWhy(l.a,l.b,sp,k),c=xpCost(sp,k,false),spn=spareN(k); h+=`
${O.n}
${xpModes(k,run)}${n?` · ${tr('link_panels.n_lit',{n})}`:''}${spn?` · ${trn('link_panels.n_spare_on_the_shelf',spn)}`:''}
${why?`
${esc(why)}
`:''}
${n&&ch.length>1?btn('−','xpCh',{id:l.id,o:k,d:-1},'ghost sm'):''}${btn(`+ ${spn?tr('link_panels.spare_price',{price:fmt$(c)}):fmt$(c)}`,'xpCh',{id:l.id,o:k,d:1},'sm',!!why||S.cash`;} h+=`

${tr('link_panels.unplugged_optics_go_on_the_spares')}

`;} h+=`${trafficSection(l)}${metricSection(l)}
${btn(UI.confirm===l.id?tr('link_panels.really_give_it_up'):tr('express.tear_down'),'rmLink',{id:l.id},'ghost sm')}

${tr('express.tear_down_note')}

`; return h;} // Where an express can go from this fiber: through either end and on over your other ROADM fibers. function xpTargets(l){const out=[];for(const [x,y] of [[l.a,l.b],[l.b,l.a]])for(const p of xpPaths(x,null,l,6))if(xpRunKm(p.sp)<=xpReachMax())out.push({from:x,...p}); return out.sort((p,q)=>p.km-q.km).slice(0,6);} // On a dark fiber's panel: the expresses riding it, and where one could go from here. function xpDfSection(l){if(l.sub)return '';const on=xpOver(l.id),rdm=isRdm(l.sys),tg=rdm?xpTargets(l):[]; // Without a ROADMaster the hint is only worth showing where another fiber of yours meets this one. const near=!rdm&&S.links.some(x=>x!==l&&x.kind==='df'&&!x.sub&&[x.a,x.b].some(c=>c===l.a||c===l.b)); if(!on.length&&!tg.length&&!near)return ''; let h=`

${tr('express.title')}

${tr('express.lead')}

`; if(!rdm)h+=`

${tr('express.needs_roadm')}

`; if(on.length)h+=`

${tr('express.riding_here')}

`+on.map(x=>`
${CITY[x.a].name} ⇄ ${CITY[x.b].name} ${linkDown(x)?''+tr('common.dark')+'':''}
${capName(x)} · ${trn('express.n_channels',(x.ch||[]).length)} · ${tr('express.city_via',{via:esc(xpVia(x))})}
${btn(tr('common.open'),'selLink',{id:x.id},'ghost sm')}
`).join('')+`

${tr('express.riding_note')}

`; if(tg.length)h+=`

${tr('express.express_to')}

`+tg.map(t=>{const cs=xpCities(t.from,t.sp);return `
${CITY[t.from].name} → ${CITY[t.to].name}
${tr('express.via_km',{via:cs.slice(1,-1).map(c=>CITY[c].name).join(', '),km:Math.round(t.km).toLocaleString()})}
${btn(tr('express.plan'),'xpOpen',{a:t.from,b:t.to,via:t.sp.map(s=>s.id).join(',')},'pink sm')}
`;}).join(''); return h+`
`;} // The link window's Express tab: the ways your fibers chain from a to b, shortest first, an optic per button. Optic // names are long: they go above the reason, not in the narrow column a wave's '400G' fits in. function xpModalBody(a,b,routes){let h=`

${tr('express.modal_lead',{a:CITY[a].name,b:CITY[b].name})}

`; for(const r of routes){const sp=r.sp,ids=sp.map(s=>s.id),cs=xpCities(a,sp),run=xpRunKm(sp),old=xpFind(a,b,ids),lat=sp.reduce((x,s)=>x+linkLat(s),0); h+=`

${tr('express.via_km',{via:cs.slice(1,-1).map(c=>CITY[c].name).join(', '),km:Math.round(r.km).toLocaleString()})}

${sp.map(s=>`
${xpSpanName(s)} · ${xpSpanMeta(s)}
`).join('')}
${tr('express.optical_run')}${run.toLocaleString()} km
${tr('common.latency')}${tr('common.ms_ms_one_way',{ms:lat.toFixed(1)})}
${old?`

${trn('express.already',(old.ch||[]).length)}

`:''}
${Object.keys(OPT).filter(k=>techOk('opt',k,OPT[k].lvl)).map(k=>{const O=OPT[k],why=xpWhy(a,b,sp,k),c=xpCost(sp,k,!old),g=xpOptG(k,run); return ``;}).join('')}
`;} return h+`

${tr('express.modal_note',{price:fmt$(XP_PASS)})}

`;}