// Leader Ops client — renders the coaching radar for the signed-in leader's own // organisation, then asks the engine for a written plan on request. (function () { 'use strict'; var $ = function (id) { return document.getElementById(id); }; function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; }); } function n(v) { return Number(v || 0).toLocaleString(); } function gate(msg) { $('lGate').style.display = 'block'; $('lGate').innerHTML = msg; } function tile(value, label, cls) { return '
' + value + '
' + '
' + label + '
'; } function renderScan(scan) { if (!scan || !scan.ready) { gate('The on-chain index is still catching up. Give it a moment and refresh.'); return; } $('lBody').style.display = 'block'; var t = scan.totals || {}; $('lTiles').innerHTML = tile(n(scan.scanned), 'positions below you', 'cool') + tile(n(t.atRiskPol), 'POL forming that someone below cannot catch', t.atRiskPol > 0 ? 'hot' : '') + tile(n(t.oneAwayCount), 'one direct short of qualifying', t.oneAwayCount > 0 ? 'hot' : '') + tile(n(t.rollForwardCount), 'qualified but still on Scintilla', ''); var out = []; if ((scan.atRisk || []).length) { var rows = scan.atRisk.map(function (r) { return '#' + esc(r.id) + '' + '' + esc(r.levelName) + '' + '' + (r.qualified ? 'upgrade to ' + esc(r.neededLevelName || '') + '' : '' + esc(r.directCount) + ' of 2 directs') + '' + '' + n(r.atRiskPol) + '' + '' + n(r.earnedPol) + '' + '' + (r.upgradeCost ? n(r.upgradeCost) : '—') + ''; }).join(''); out.push('

Money forming they can\'t catch

' + '
A position only catches an upgrade payment if it is qualified and already at or above the level being bought. These people have activity underneath them that is passing them by — the fastest, kindest conversation you can have this week.
' + '
' + rows + '
PositionLevelWhat they needPOL passing themEarnedUpgrade cost
'); } if ((scan.rollForward || []).length) { var rf = scan.rollForward.map(function (r) { return '#' + esc(r.id) + '' + n(r.earnedPol) + '' + n(r.ascensusCost) + ''; }).join(''); out.push('

Already qualified, still on Scintilla

' + '
They have their two and their entry rewards are sitting there. Ascensus is the upgrade that starts catching their directs\' payments — for several of these, what they have already earned covers it.
' + '
' + rf + '
PositionEarned (POL)Ascensus costs
'); } if ((scan.oneAway || []).length) { out.push('

One direct short

' + '
A single placement qualifies each of these. If you have anyone coming in, this is where to put them.
' + '
' + scan.oneAway.map(function (r) { return '#' + esc(r.id) + ' (' + esc(r.levelName) + ')'; }).join('  ·  ') + '
'); } if (!out.length) { out.push('

Nothing needs chasing

' + '
Nobody below you is one direct short, sitting on uncatchable money, or qualified but stuck on Scintilla. That is the quiet week you spend working on your own two.
'); } $('lSections').innerHTML = out.join(''); } async function writePlan(btn) { btn.disabled = true; btn.innerHTML = 'Reading your organisation…'; $('lErr').style.display = 'none'; try { var r = await fetch('/api/public/suite-leader', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' }); var d = await r.json(); if (!r.ok) { $('lErr').textContent = d.error || 'Could not write the plan just now.'; $('lErr').style.display = 'block'; } else { $('lDigest').textContent = d.text || ''; $('lDigest').style.display = 'block'; if (d.scan) renderScan(d.scan); } } catch (e) { $('lErr').textContent = 'Connection hiccup — try again.'; $('lErr').style.display = 'block'; } btn.disabled = false; btn.innerHTML = '🧭 Write this week\'s coaching plan'; } async function boot() { try { var r = await fetch('/api/public/suite-leader'); if (r.status === 401) { gate('You’re not signed in yet. Open the Suite and connect the wallet that holds your position, then come back.'); return; } if (r.status === 403) { var g = await r.json(); gate((g.error || 'Not open for this position yet.') + ' See your Suite.'); return; } if (!r.ok) return; var d = await r.json(); renderScan(d.scan); if (d.writerReady === false) { $('lWrite').disabled = true; $('lWrite').textContent = 'The writer is warming up'; } } catch (e) {} } document.addEventListener('DOMContentLoaded', function () { boot(); $('lWrite').addEventListener('click', function () { writePlan(this); }); }); })();