from pathlib import Path
import re,json,shutil,html
r=Path('/Users/vengurnagu/Desktop/Sense India');tmp=Path('/private/tmp/sense-assessments');data=json.loads((tmp/'data-final.json').read_text())
for p in tmp.glob('*.html'):
 shutil.copy2(p,r/'output/mockups'/p.name)
 s=p.read_text().replace('href="../../"','href="../../../"').replace('href="../pdf/','href="../../pdf/')
 (r/'output/mockups/client'/p.name).write_text(s)
refs=r/'reference-documents/Additional Assessments';refs.mkdir(exist_ok=True)
for name in ['Young Adult - english and hindi final.pdf',"SII Physiotherapy Assessment Tool-Jan'26.docx",'POSTURE & GAIT DEVIATION LIST.docx','Flow Chart to maintain the documents in the programme.pdf','Children - english and hindi final.pdf']:shutil.copy2(Path('/Users/vengurnagu/Downloads')/name,refs/name)
shutil.copy2(refs/'Flow Chart to maintain the documents in the programme.pdf',r/'output/pdf/programme-documentation-flowchart.pdf')
entries=[('child-mental-health-mockups.html','Child Mental Health Screening','10–18 years'),('young-adult-mental-health-mockups.html','Young Adult Mental Health Screening','19–29 years'),('physiotherapy-assessment-mockups.html','Physiotherapy Assessment','Posture, gait and IEP-linked goals')]
icon='<span class="card-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="23" height="23" fill="none" stroke="currentColor" stroke-width="1.8"><rect x="5" y="5" width="14" height="16" rx="2"/><path d="M9 3h6v4H9zM9 12h6m-6 4h6"/></svg></span>'
for filename,client in [('DEMO_HOME.html',False),('output/mockups/client-demo.html',True)]:
 p=r/filename;s=p.read_text()
 cards=''.join('<a class="card" href="'+('client/' if client else 'output/mockups/')+url+'"><span class="card-label">'+icon+'<span>'+title+'</span></span><b>'+subtitle+' →</b></a>' for url,title,subtitle in entries)
 section='<section id="additional-assessments"><h2>Additional assessments · Phase 1</h2><div class="grid">'+cards+'</div></section>'
 if 'id="additional-assessments"' not in s:
  anchor='<footer>' if client else '<div class="resource-columns">';s=s.replace(anchor,section+anchor,1)
 if not client:
  m=re.search(r'<section id="mockup-previews">.*?</section>',s,re.S)
  if m:
   block=m.group().replace('</ul>',''.join('<li><a href="output/mockups/'+u+'" target="_blank" rel="noopener">'+t+'</a></li>' for u,t,_ in entries)+'</ul>');s=s[:m.start()]+block+s[m.end():]
  m=re.search(r'<section id="workflow-diagrams">.*?</section>',s,re.S)
  if m:
   block=m.group().replace('</ul>','<li><a href="output/mockups/programme-documentation-workflow.html">Programme documentation workflow</a></li></ul>',1);s=s[:m.start()]+block+s[m.end():]
 p.write_text(s)
# Add configuration lists alongside existing Super Admin master definitions.
addition="def('Disability & health','posturedeviations','Posture deviations',"+json.dumps(data['postures'])+");\ndef('Disability & health','gaitdeviations','Gait deviations',"+json.dumps(data['gaits'])+");\n"
for p in [r/'visualizations/super-admin-workflow.html',r/'output/mockups/client/super-admin-workflow.html']:
 s=p.read_text()
 if "'posturedeviations'" not in s:
  assert 'let masterData=' in s;s=s.replace('let masterData=',addition+'let masterData=',1);p.write_text(s)
source=(r/'visualizations/super-admin-workflow.html').read_text()
(r/'output/mockups/super-admin-workflow.html').write_text('<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Sense India Super Admin</title><style>body{margin:0;padding:20px;font:14px system-ui;color-scheme:light}</style></head><body>'+source+'</body></html>')
work=r/'work/additional-assessments';work.mkdir(exist_ok=True)
for name in ['app.js','build.py','extract.py','install.py','data-final.json']:shutil.copy2(tmp/name,work/name)
print('Installed new forms on both demo pages, programme workflow reference and 2 Super Admin masters. Source documents preserved in project.')
