const OPS_TPL_L={bb:N_('ops.tpl_bb'),transit:N_('ops.tpl_transit'),ix:N_('ops.tpl_ix'),kit:N_('ops.tpl_kit')};
// The Ops panel: the intern, their shift log, and the standing orders with their dials. A bottom sheet on phones.
function opsCard(){if(!S)return '';const last=opsHired()&&S.ops.log[0];
return `
${opsHired()?`${INTERNS[S.ops.intern].i} ${esc(tr('ops.ops_name',{name:opsName(true)}))}`:`🧑💻 ${tr('ops.standing_orders')}`}
${opsHired()?esc(last?opsEntry(last):tr('ops.l_quiet',{name:opsName()})):opsCanHire()?tr('ops.hire_pitch_short'):tr('ops.locked',{lv:2})}
${btn(opsHired()?tr('ops.standing_orders'):tr('ops.hire_an_intern'),'opsOpen',{},opsHired()?'sm':'pink sm',!opsHired()&&!opsCanHire())}
`;}
const opsEntry=e=>(e.f!==undefined?opsFFLine(e)+' ':'')+(e.r.length||e.f===undefined?opsLine(e):'');
function opsVal(k,p){const P=OPSK[k].p[p],v=opsP(k,p);return p==='prov'?(v==='cheap'?tr('ops.cheapest'):NET[v].name):P.f(v);}
function opsOrderHtml(d){const k=d.k,on=S.ops.on[k],cap=d.cap?opsCap(k):0,sp=S.ops.spent[k]||0,am=Math.round(S.ops.addMo[k]||0);
return `${d.i} ${tr(d.t)}
${tr(d.d)}${k==='caches'?' '+tr('ops.caches_rent',{price:fmt$(CACHE_MO)}):''}
${on?tr('common.on'):tr('ops.paused')}
${on?`
${Object.keys(d.p).map(p=>btn(`${tr(d.p[p].l)}: ${esc(opsVal(k,p))} `,'opsParam',{k,p},'ghost sm')).join('')}
${d.cap?btn(`${d.mo?tr('ops.budget_running'):tr('ops.budget')}: ${cap?tr('common.price_mo',{price:(d.mo?'+':'')+fmt$(cap)}):tr('ops.no_cap')} `,'opsCap',{k},'ghost sm'):''}
${sp||am?`
${tr('ops.spent_and_mo',{price:fmt$(sp),mo:opsMo$(am)})}
`:''}
${k==='ix'&&ppol()!=='open'?`
${tr('link_panels.off_while_your_peering_policy_is',{pol:tr(PPOL_N[ppol()])})}
`:''}`:''}
`;}
function opsModal(){if(!S)return;const hired=opsHired();let h=`${I.i}
${btn(tr('ops.hire_mo',{price:fmt$(INTERN_MO)}),'opsHire',{id},'pink sm',S.cash
`).join('');
openModal(h+opsOnceHtml(),'ops');return;}
const O=S.ops,I=INTERNS[O.intern];
h+=`
${I.i} ${tr(I.n)}
${tr('ops.salary',{price:fmt$(INTERN_MO),d:dateStr(O.hired)})}
${btn(UI.confirm==='opsFire'?tr('ops.really_fire'):tr('ops.fire'),'opsFire',{},'ghost sm')}
${O.log.length?`
${O.log.slice(0,6).map(e=>esc(tr('peering_inbox.day_d',{d:e.d})+': '+opsEntry(e))).join('\n')} `:''}
${ibx().bot?tr('ops.lpm_on',{name:opsName()}):tr('ops.lpm_off',{name:opsName()})}
${btn(`${tr('ops.floor')}: ${O.floor?fmt$(O.floor):tr('ops.no_cap')} `,'opsFloor',{},'ghost sm')}
`;
h+=`
${tr('ops.how_it_works',{name:opsName()})}
`+OPS.map(opsOrderHtml).join('');
// Per POP: switch single orders off where the player wants to decide by hand.
const cities=Object.keys(S.pops).sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name)),c=S.pops[UI.opsCity]?UI.opsCity:cities[0];
if(c)h+=`
${tr('ops.per_pop')} ${tr('common.your_pop')}${cities.map(x=>`${esc(CITY[x].name)} `).join('')}
${OPS_POP.map(k=>{const here=opsHere(k,c);return `${OPSK[k].i} ${tr(OPSK[k].t)} `;}).join('')}
${tr('ops.per_pop_note')}
`;
h+=`
${tr('ops.template')} ${tr('ops.template_note',{name:opsName()})}
${OPS_TPL.map(k=>`${tr(OPS_TPL_L[k])} `).join('')}
`;
h+=opsOnceHtml();openModal(h,'ops');}
// The big one-off batches (#181, #192) live here now, next to the orders that run them every week.
const opsOnceHtml=()=>`
${tr('ops.by_hand')} ${tr('ops.by_hand_note')}
${btn(tr('utilities.title'),'utilities',{},'sm')}${btn(tr('pni_all.peer_all_networks'),'pniAllOpen',{net:null},'sm')}
`;
// On a city without a POP: open it from the template in one tap.
function opsTplHtml(c){if(!opsHired())return '';const q=opsTplQuote(c);if(!q)return '';
return `
${tr('ops.template')} ${esc(tr('ops.tpl_offer',{name:opsName(),list:[tr('ops.tpl_pop'),...q.parts].join(', ')}))}
${btn(tr('ops.tpl_open',{cost:fmt$(q.cost)}),'opsNewPop',{city:c},'pink',S.cash`;}