{const r=C.setServer(a.value);msg.textContent=r.ok?'Address saved.':r.reason;}},'Save address');
const upd=h('button',{class:'btn small',type:'button',onclick:async()=>{upd.disabled=true;msg.textContent='Contacting the registry…';let r;try{r=await C.refresh();}catch(e){r={ok:false,reason:'The registry could not be reached.'};}msg.textContent=r.ok?'Updated: '+r.entries+' fingerprints.':r.reason;upd.disabled=false;}},'Get latest update');
const tok=h('input',{type:'text',id:'regtok',placeholder:'Community token (msn_…)','aria-label':'Community token'});
const si=h('button',{class:'btn small',type:'button',onclick:async()=>{const r=await C.signIn(tok.value);msg.textContent=r.ok?'Signed in.':r.reason;}},'Sign in');
shell(p,'Community Fake Project',[h('div',{class:'card'},h('p',null,'CoCreators flag suspect pictures, recordings and video. Two different reviewers must agree before a label is published. Checking a file always stays on your device.'),h('label',{class:'note'},'Registry address'),a,h('div',{class:'row',style:'margin-top:8px'},save,upd),h('label',{class:'note',style:'display:block;margin-top:8px'},'Community token (only needed to send reports)'),tok,h('div',{class:'row',style:'margin-top:8px'},si),msg),fr]);});}
/* ---------- My data ---------- */
function openData(){openPage('data','My data',p=>drawData(p));}
function drawData(p){
const cap=capMB(),pct=Math.min(100,usedMB()/cap*100),body=[];
body.push(h('div',{class:'card'},h('div',{class:'row'},h('h2',null,'My data'),h('span',{class:'tag real'},'Free in every version')),h('p',{class:'note'},'Your own documents and notes, searched on this phone and never uploaded. Choose text files (.txt, .md, .csv). '+(store.persistent()?'They are kept on this device between sessions. They are not encrypted in this review model.':'This browser did not allow storage, so files last only until you close the page.'))),
h('div',{class:'card'},h('p',{class:'note'},'Limit for this phone: '+cap+' MB. Used: '+usedMB().toFixed(2)+' MB.'),h('div',{class:'meter'},h('i',{style:'width:'+pct+'%'}))));
const fi=h('input',{type:'file',id:'docfile',multiple:true,accept:'.txt,.md,.csv,text/plain','aria-label':'Choose text files'});
fi.onchange=async()=>{S.docMsg='';for(const f of fi.files){if(usedMB()+f.size/1048576>cap){S.docMsg='Not added: "'+f.name+'" would go over this phone\'s limit of '+cap+' MB.';break;}await store.add({name:f.name,size:f.size,text:await f.text(),added:Date.now()});S.docs=await store.all();}drawData(p);};
body.push(fi,h('p',{class:'note warn','aria-live':'polite'},S.docMsg));
if(!S.docs.length)body.push(h('button',{class:'btn small',type:'button',id:'exfiles',onclick:async()=>{await store.add({name:'Example: boiler service.txt',size:120,text:'Boiler service booked for Tuesday 4 November at 10:00. Engineer will bring a replacement valve. Keep the gas safety certificate.',added:Date.now()});await store.add({name:'Example: trip notes.txt',size:150,text:'Lisbon trip: flights Friday evening. Hotel near the river. Do not forget the charger and the printed tickets.',added:Date.now()});S.docs=await store.all();drawData(p);}},'Add two example files'));
else{const q=h('input',{type:'search',id:'docq',placeholder:'Search your files','aria-label':'Search your files'}),res=h('div',{'aria-live':'polite'});
q.oninput=()=>{res.replaceChildren();const t=q.value.trim();if(t.length<2)return;const r=searchDocs(t,5);if(!r.length)res.append(h('p',{class:'note'},'No match in your usable files.'));r.forEach(x=>res.append(h('div',{class:'res dat'},h('b',null,x.name),h('div',null,x.snip))));};
body.push(h('div',{class:'card'},S.docs.map(d=>h('div',{class:'row',style:'margin:4px 0'},h('span',null,d.name),d.text.trim().length<40?h('span',{class:'tag demo'},'Too short to use as evidence'):null,h('button',{class:'btn small',type:'button','aria-label':'Remove '+d.name,onclick:async()=>{await store.del(d.id);S.docs=await store.all();drawData(p);}},'Remove')))),q,res,
h('button',{class:'btn small',type:'button',id:'delall',onclick:async()=>{if(!S.delArm){S.delArm=true;drawData(p);return;}await store.clear();S.docs=[];S.delArm=false;drawData(p);}},S.delArm?'Press again to delete everything':'Delete all my data'));}
shell(p,'My data',body);}
function setTier(t){try{if(root.__mysniSetTier)root.__mysniSetTier(t);else ls.set('mysni-tier-v2',t);}catch(e){}try{if(root.refreshTier)root.refreshTier();}catch(e){}}
/* ---------- Email Cleaner and MyWorkshop: the real screens, run on test data ---------- */
function embedPage(id,title,docId,sandbox,healthUrl){openPage(id,title,p=>{if(p.dataset.built)return;p.dataset.built='1';
const el=document.getElementById(docId);const src=el?el.textContent.replace(/<@\/script/gi,'Not available';
const fr=h('iframe',{title:title,sandbox:sandbox,id:'fr-'+id,style:'flex:1;min-height:0;width:100%;border:0;background:#070d17'});fr.srcdoc=(docId==='x5-wsdoc'||docId==='x5-ecdoc')?withOwner(src):src;
const badge=h('span',{class:'tag demo'},'Preview');if(healthUrl)serviceBadge(badge,healthUrl);p.replaceChildren(h('div',{class:'bar'},h('button',{class:'btn small back',type:'button',onclick:()=>closePage(id)},'← MySNI app'),h('b',null,title),badge),fr);});}
function openEmail(){return window.__mysniLocked('email');embedPage('email','Email Cleaner','x5-ecdoc','allow-scripts allow-forms allow-downloads','http://127.0.0.1:8783/api/health');}
function openWork(){return window.__mysniLocked('work');embedPage('work','MyWorkshop','x5-wsdoc','allow-scripts allow-downloads allow-modals','http://127.0.0.1:8782/api/health');}
/* ---------- Community (the MySNI CoCreators page, as on the website) ---------- */
const CCK='mysni.x5.ccstore';let ccStore={};try{ccStore=JSON.parse(ls.get(CCK)||'{}');}catch(x){}
function ccDoc(id,hash){const el=document.getElementById(id);let src=el?el.textContent.replace(/<@\/script/gi,'Not available';
const inj='Not available';
const inj='