const portMo=v=>v?tr('common.price_mo',{price:fmt$(v)}):tr('common.free');
function ixSection(c){const ids=ixIdsIn(c);if(ids.length<2)return ixBlock(c,false);
let h=` ${tr('link_panels.n_exchanges_compete_in_city_members',{n:ids.length,city:esc(CITY[c].name)})} ${tr('link_panels.running_an_exchange_in_mainland')} ${tr('link_panels.there_s_no_ix_in_city',{city:C.name})}${tr('common.internet_exchanges')}
${multi?esc(ix)+(X?' '+tr('common.challenger')+'':' '+tr('common.incumbent')+''):tr('common.internet_exchange')}
`;
if(!ix&&C.cn){h+=`
${tr('link_panels.ix_is_a_shared_switch_one',{ix:esc(ix),list:(()=>{const m=ixMembers(c),big=m.filter(id=>!NET[id].tail),t=m.length-big.length;return (big.map(id=>esc(NET[id].name)).join(', ')||tr('common.nobody_yet'))+(t?trn('link_panels.plus_n_small_network',t):'');})()})}
${S.pops[city]?'':REMOTE_WARN}${X?`${esc(X.blurb)} ${X.freeTo!==undefined?tr('link_panels.ports_up_to_port_are_free',{port:PORT[X.freeTo].n}):tr('link_panels.ports_at_p_of_the_usual',{p:Math.round(ixMul(c)*100)})}
`:''}${CITY[city].ixCheap?`${tr('link_panels.run_by_a_nonprofit_public_prices')}
`:''}${isDk(c)?`${tr('link_panels.run_by_de_kicks_group_no')}
`:''}${rt&&rt>S.day?tr('link_panels.de_kicks_personalised_pricing_p_of',{p:Math.round(dkMult(c)*100),n:rt-S.day}):tr('link_panels.de_kicks_personalised_pricing_p_of_3d4f',{p:Math.round(dkMult(c)*100)})}
`; for(const x of ad)h+=`${trn('link_panels.remote_port_via_a_reseller_1',ixMembers(c).filter(noRemote).length)}
`; if(mine){const f=S.myIx[c].fab|0,N=MYIX_FAB[f+1];h+=`${tr('link_panels.a_bigger_fabric_carries_more_traffic')}
`:''+tr('link_panels.biggest_fabric_money_can_buy')+'
'}`;} else h+=`${tr('link_panels.name_is_down_nothing_you_can',{name:esc(f.name)})}
${tr('link_panels.remote_peering_leg_into_ix',{ix:esc(CITY[l.b].ix)})}
`:''}${tr('link_panels.no_traffic_right_now')}
${tr('link_panels.totals_for_all_n_links_between',{n})}
`:''}${tr('link_panels.biggest_feeder_egress_in_city_set',{egress:esc(d.lab),city:CITY[d.city].name})}
`;} return h+``; } function metricSection(l){const cur=l.metric||'normal'; return `${tr('link_panels.your_routers_pick_the_lowest_cost')}
${tr('link_panels.mainland_china_plays_by_its_own',{list:CN_BLOCKED.slice(0,4).map(esc).join(', '),pct:pct(loss)})}
`; if(st==='none')h+=`${tr('link_panels.foreign_networks_need_a_local_joint')}
${btn(tr('link_panels.apply_for_a_license_price_mo',{price:fmt$(CN_LIC),mo:fmt$(CN_JV_MO)}),'applyCn',{},'pink',S.cash${tr('link_panels.your_joint_venture_holds_an')}
`; if(R.gfwCross>0.5)h+=`${tr('common.better_terminals_and_optical_tuning')}
`+Object.entries(SUB_UPGRADES).map(([k,U])=>{ const at=l['sub'+k],done=subUpgradeReady(l,k),cost=subUpgradeCost(l,k),preview={...l,['sub'+k]:S.day}; const status=done?tr('common.installed'):at!==undefined?tr('link_panels.ready_in_n_days',{n:Math.max(0,at-S.day)}):tr('link_panels.price_n_days',{price:fmt$(cost),n:U.days}); return `${tr('link_panels.you_can_pre_install_optics_now')}
`;} else if(inc&&linkDown(l))h+=`${esc(inc.msg)}
${inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash${tr('link_panels.this_fiber_is_dark_add_optics')}
`:''}${tr('link_panels.other_carriers_rent_what_you_do')}
${tr('link_panels.nothing_spare_to_sell_on_this')}
`}${tr('link_panels.each_channel_is_a_pair_of')}
`; if(l.own&&l.sub)h+=subUpgradePanel(l); for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k); const md=optMode(k,l),cc=chCost(l,k),sp=spareN(k); h+=`${tr('link_panels.unplugged_optics_go_on_the_spares')}
`; {const used=[...new Set(l.ch||[])].filter(k=>OPT[k]&&OPT[k].lvl<=lvl());if(used.length)h+=`${tr('link_panels.a_regen_site_turns_the_light',{price:fmt$(REGEN_MO)})}
${l.sub&&l.own?`${tr('link_panels.no_regen_sites_in_the_middle')}
`:`${esc(sysD.blurb)}
${tr('link_panels.spare_optics_and_amplifier_cards_on')}
`; {const sib=pairLinks(l.a,l.b).filter(x=>x!==l&&x.kind!=='vxc');h+=`${sib.length?tr('link_panels.other_links_between_these_cities'):tr('link_panels.this_is_the_only_link_between')}
${sib.map(x=>`${tr('link_panels.giving_it_up_now_returns_price',{price:fmt$(cabBack(l))})}
`:''}${inc?esc(inc.msg):''} ${tr('link_panels.back_in_n_days',{n:l.cut-S.day})}
${inc&&inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash${tr('link_panels.congested_upgrade_it_or_add_a')}
`:''}${mates.length?trn('link_panels.shares_a_trench_with_n_other',mates.length):sib.length?tr('link_panels.runs_on_its_own_route_a'):tr('link_panels.this_is_the_only_link_between')}
${sib.map(x=>`${tr('link_panels.collecting_data_check_back_in_a')}
`; let ymax=1;for(const r of rows){let s=0;for(const k of stackKeys)s+=r[k]||0;ymax=Math.max(ymax,s);for(const ln of lines)ymax=Math.max(ymax,r[ln.k]||0);}ymax*=1.1; const x=i=>L+(W-L-Rr)*i/(rows.length-1),y=v=>T+(H-T-B)*(1-v/ymax);let g=''; for(let j=0;j<=3;j++){const v=ymax*j/3,yy=y(v);g+=`