import {parseStorageReport} from './storage-parser.js';
const bytes=value=>{const units=['B','KB','MB','GB','TB'];const index=Math.min(4,Math.floor(Math.log10(Math.max(1,value))/3));return `${new Intl.NumberFormat('en',{maximumFractionDigits:index===4?2:1}).format(value/1000**index)} ${units[index]}`;};
export function renderStorage(input){
const panel=document.querySelector('#storage');
if(!input)return;
try{
const report=parseStorageReport(input);
if(report.probes.length!==3||report.segmentCount<3||report.sealedFileBytes<=0)throw Error('Invalid storage report');
for(const p of report.probes){
const values=[p.fileBytes,p.compressedFrameBytes,p.uncompressedBlockBytes,p.framingBytes,p.headerBytes,p.footerBytes,p.mixedNamespaceFrameBytes];
if(values.some(n=>!Number.isSafeInteger(n)||n<0)||p.uncompressedBlockBytes===0||p.compressedFrameBytes===0||p.mixedNamespaceFrameBytes>p.compressedFrameBytes||p.fileBytes!==p.compressedFrameBytes+p.framingBytes+p.headerBytes+p.footerBytes)throw Error('Storage accounting mismatch');
}
panel.hidden=false;
panel.innerHTML=`
Across ${report.segmentCount.toLocaleString()} completed files. This measures those files, not all storage used by Stream.
We inspected three files. Choose one to see how it’s stored.
Measured ${new Date(report.measuredAt).toLocaleString()}. These three files do not establish averages for the whole archive. Sizes use decimal units.
● Compressed data ${bytes(p.compressedFrameBytes)}● Indexes and framing ${bytes(overhead)}
${sharedText} of this file’s compressed data is in blocks shared by multiple sources. These are groups of records compressed together.
That’s why the number of events alone can’t tell us how much disk space each source uses.
File ${p.index+1} of ${report.segmentCount}; ${p.blocks.toLocaleString()} blocks; ${p.collections.toLocaleString()} collection-index entries.
The full file size includes compressed frames, their length prefixes, the header, and the footer. The first bar measures uncompressed block bodies only. Shared means more than one namespace (or account-level marker) occurs in a block; shared bytes are counted once.
Only headers and indexes were fetched. Record bodies and media were not downloaded. No per-source byte estimates or claims about reclaimable space are made.
The saved report could not be validated. The sphere map is still available.
';} }