// Corrino Group market display: never manufacture prices or executive identities. export const CORRINO_MARKET_FEED='/api/companies/market'; export function isVerifiedMarketPayload(data){ return !!data&&data.verified===true&&typeof data.symbol==='string'&&/^[A-Z0-9._-]{1,16}$/.test(data.symbol)&& Array.isArray(data.history)&&data.history.length>=2&&data.history.length<=500&& data.history.every((row,i)=>Number.isSafeInteger(row.timestamp)&&Number.isFinite(row.price)&&row.price>=0&&(i===0||row.timestamp>data.history[i-1].timestamp)); } export function marketChartPoints(history,width=800,height=240){ if(!Array.isArray(history)||history.length<2)return ''; const prices=history.map(r=>r.price),min=Math.min(...prices),max=Math.max(...prices),span=max-min||1; return prices.map((p,i)=>`${(i/(prices.length-1)*width).toFixed(1)},${((max-p)/span*height).toFixed(1)}`).join(' '); } async function loadMarket(){ const chart=document.querySelector('#exchange .chart'),status=document.querySelector('#exchange .market-status'); if(!chart||!status)return; try{const response=await fetch(CORRINO_MARKET_FEED,{cache:'no-store',credentials:'omit'});if(!response.ok)return; const data=await response.json();if(!isVerifiedMarketPayload(data))return; const ns='http://www.w3.org/2000/svg',svg=document.createElementNS(ns,'svg');svg.setAttribute('viewBox','0 0 800 240');svg.setAttribute('role','img');svg.setAttribute('aria-label',`Verified ${data.symbol} historical price movement`);svg.classList.add('market-line'); const line=document.createElementNS(ns,'polyline');line.setAttribute('points',marketChartPoints(data.history));line.setAttribute('fill','none');line.setAttribute('stroke','#dfc58e');line.setAttribute('stroke-width','3');line.setAttribute('vector-effect','non-scaling-stroke');svg.append(line); chart.replaceChildren(svg);status.textContent='VERIFIED MARKET DATA'; const fields=document.querySelectorAll('#exchange .market-bottom strong');if(fields[0])fields[0].textContent=data.symbol;if(fields[1])fields[1].textContent=String(data.history.at(-1).price);if(fields[2])fields[2].textContent='Historical data'; }catch{/* Offline, absent or invalid market API: keep explicit unavailable state. */} } if(typeof document!=='undefined')loadMarket(); // Active companies are public; CEO names come from registered account records. export function validCompanyList(data){return Array.isArray(data?.companies)&&data.companies.length<=500&&data.companies.every(c=>typeof c.slug==='string'&&/^[a-z][a-z0-9-]{2,63}$/.test(c.slug)&&typeof c.name==='string'&&c.name.length<=120&&(c.ceo===null||typeof c.ceo==='string'));} async function loadCompanies(){const section=document.querySelector('#divisions');if(!section)return;try{const response=await fetch('/api/companies',{cache:'no-store',credentials:'omit'});if(!response.ok)return;const data=await response.json();if(!validCompanyList(data))return;const wrapper=document.createElement('div');wrapper.className='company-register';const heading=document.createElement('h3');heading.textContent='Registered companies';wrapper.append(heading);if(!data.companies.length){const p=document.createElement('p');p.textContent='No active companies registered yet.';wrapper.append(p);}for(const company of data.companies){const card=document.createElement('article');const name=document.createElement('h4');name.textContent=company.name;const ceo=document.createElement('p');ceo.textContent='CEO: '+(company.ceo||'Not appointed');card.append(name,ceo);wrapper.append(card);}section.append(wrapper);}catch{/* Preserve static divisions when the registry is unavailable. */}} if(typeof document!=='undefined')loadCompanies();