`).join('');
const summary=`${l.name} · ${f.name} · ${p.name} · ${modeName(state.mode)}`;
$('selection-summary').textContent=`Current preview: ${summary}.`;
persist();
if(shouldAnnounce) announce(`Preview changed to ${summary}.`);
}
const messages={ready:['conversation','Ready. Try a local success preview.'],loading:['dim','Loading specimen. No request is running. Choose another state to continue.'],empty:['plus','No projects in this example. Your next step would be to create one.'],error:['error','Could not save this example. Your text is unchanged. Use Preview success to try again.'],success:['check','Success preview. No project was created or saved to a server.']};
function sample() {
const state=$('sample-state').value, [icon,message]=messages[state];
$('sample-feedback').dataset.state=state;
$('sample-feedback').innerHTML=B.icon(icon)+`${message}`;
$('sample-action').disabled=state==='loading';
$('sample-title').setAttribute('aria-describedby','sample-help sample-feedback');
}
$('sample-state').addEventListener('change',sample);
$('sample-action').addEventListener('click',()=>{$('sample-state').value='success';sample();});
$('reset').addEventListener('click',()=>{state={...defaults};update();announce('Preview reset. Your review notes and example project name are unchanged.');});
function download(name,type,content) {
const url=URL.createObjectURL(new Blob([content],{type}));
const a=document.createElement('a');a.href=url;a.download=name;a.click();
// Browser downloads consume the URL before the next task; retain briefly for portability.
setTimeout(()=>URL.revokeObjectURL(url),1000);
announce(`${name} prepared for download. Check your browser downloads.`);
}
$('export').addEventListener('click',()=>{
const p=B.palettes.find(p=>p.id===state.palette);
download(`mosaic-${p.id}-tokens.json`,'application/json',JSON.stringify({prototype:true,palette:p.name,theory:p.theory,rationale:p.note,modes:Object.fromEntries(modes.map(mode=>[mode,B.tokens(p,mode)]))},null,2));
});
$('review-notes').addEventListener('input',()=>{
try{localStorage.setItem('mosaic-brand-notes-v1',$('review-notes').value);}catch{storageAvailable=false;announce('Notes cannot be stored in this browser. Download them before closing.');}
});
$('download-review').addEventListener('click',()=>{
download('mosaic-brand-review.txt','text/plain',`Mosaic Stack branding review\n${$('selection-summary').textContent}\n\n${$('review-notes').value||'No written notes yet.'}\n\nThese selections are review preferences, not an automatic approval.\n`);
});
update(false);sample();
if(!storageAvailable) announce('Browser storage is unavailable. The preview still works. Download notes to keep them.');
})();