Blood Pressure
Morning
Before 10 AM
Evening
After 6 PM
Medicines
BP Tablet
Morning ยท After breakfast
Multivitamin
Evening ยท After dinner
No custom fields
';return} let html=''; cfs.forEach((f,i)=>{ html+=`No other members yet
'; openSheet('perm-sheet'); } function savePermissions(){ if(!pendingPermId)return; const others=Object.keys(state.profiles).filter(id=>id!==pendingPermId); const canView=others.filter(oid=>{ const t=document.getElementById('perm-toggle-'+oid); return t&&t.classList.contains('on'); }); state.permissions[pendingPermId]={canView,canViewAll:canView.length===others.length}; closeSheet('perm-sheet'); renderAdmin(); } function openDeleteSheet(pid){ pendingDeleteId=pid; const p=state.profiles[pid]; document.getElementById('delete-sheet-sub').textContent=`You are about to delete ${p.name}'s profile and all their health data.`; openSheet('delete-sheet'); } function confirmDelete(){ if(!pendingDeleteId)return; delete state.profiles[pendingDeleteId]; delete state.data[pendingDeleteId]; delete state.permissions[pendingDeleteId]; closeSheet('delete-sheet'); renderAdmin(); } /* ===================== ADD MEMBER ===================== */ function addMember(){ const name=document.getElementById('new-member-name').value.trim(); if(!name){alert('Enter a name.');return} const relation=document.getElementById('new-member-relation').value; const color=document.getElementById('new-member-color').value; const uid='member_'+Date.now(); state.profiles[uid]={uid,name,relation,email:'',color,init:name[0].toUpperCase(),isAdmin:false}; state.permissions[uid]={canView:[],canViewAll:false}; closeSheet('add-member-sheet'); document.getElementById('new-member-name').value=''; renderAdmin(); } /* ===================== TABS ===================== */ function switchTab(tab,el){ document.querySelectorAll('.tab').forEach(t=>t.classList.remove('active')); if(el)el.classList.add('active'); ['today','history','trends','settings','admin'].forEach(t=>{ const el=document.getElementById('tab-'+t); if(el)el.style.display=t===tab?'block':'none'; }); state.activeTab=tab; if(tab==='trends')renderTrends(); if(tab==='history')renderHistory(); if(tab==='admin')renderAdmin(); if(tab==='settings'){renderCustomFields();} if(tab==='today')initToday(); } /* ===================== SHEETS ===================== */ function openSheet(id){ if(id==='profile-sheet')renderProfileSheet(); document.getElementById(id).classList.add('open'); } function closeSheet(id){document.getElementById(id).classList.remove('open')} document.addEventListener('click',e=>{ if(e.target.classList.contains('overlay'))e.target.classList.remove('open'); }); /* ===================== PWA INSTALL ===================== */ let deferredPrompt=null; window.addEventListener('beforeinstallprompt',e=>{ e.preventDefault();deferredPrompt=e; const b=document.createElement('button'); b.className='banner blue';b.style.cssText='width:100%;border:none;cursor:pointer;text-align:left;margin-bottom:12px'; b.innerHTML='๐ฒAdd to Home Screen for quick access'; b.onclick=()=>{deferredPrompt.prompt();b.remove()}; const c=document.getElementById('content');if(c.firstChild)c.insertBefore(b,c.firstChild); });