"""Rebuild symposia.html with the human content of META 2026 in META 2027's language.

What returns from 2026: the six full titles, the eighteen chairs *with their portraits* (copied to
images/chairs/, never hotlinked — including the one that lived on aesconference.org), the
descriptions and the seventy topics. What does not: any invited speaker. Each symposium carries
one quiet line — announced once confirmed — instead of a list of names nobody has re-invited.

The English of the descriptions is proofread, not rewritten: broken sentences mended, articles
fixed, "light scatters" corrected to "scatterers". The science is untouched and no sentence was
made to sell anything.
"""

import html
import json
import re

syms = json.load(open('../symposia_full.json', encoding='utf-8'))

# ---------------------------------------------------------------- proofreading
# Sentence-level repairs, applied to the extracted text so the diff against the source is
# explicit. Meaning preserved; register kept academic.
FIXES = {
    # I — articles and plural noise
    'studies on optically active hybrid nanomaterials':
        'studies of optically active hybrid nanomaterials',
    'applications of the optically active materials, including the bottom-up syntheses, '
    'top-down nanofabrication, chemical and physical examinations of new properties of such '
    'new hybrid optically active nanomaterials':
        'applications of optically active materials, including bottom-up synthesis, top-down '
        'nanofabrication, and the chemical and physical examination of the new properties of '
        'these hybrid nanomaterials',
    # III — a typo and a sentence with no verb
    'subwavelength anisotropic light scatters (optical antennas)':
        'subwavelength anisotropic light scatterers (optical antennas)',
    'Within last few years significant progress, design of metasurfaces that refract and focus '
    'light, enabling many unique properties and applications such as holograms, optical vortex '
    'generation/detection, ultrathin focusing lens, perfect absorber, etc.':
        'Recent years have seen significant progress in the design of metasurfaces that refract '
        'and focus light, enabling unique properties and applications such as holograms, optical '
        'vortex generation and detection, ultrathin focusing lenses and perfect absorbers.',
    'and particularly aim to explore on new materials, structures, and advanced optical '
    'science/functionality of metasurfaces for applications spanning from imaging system, '
    'bio/chemical sensing, energy harvesting devices, communication system, and data storage':
        'and aims in particular to explore new materials, structures and advanced optical '
        'functionalities of metasurfaces, for applications spanning imaging, bio- and chemical '
        'sensing, energy harvesting, communications and data storage',
    # IV — the question rebuilt as a question
    'Chirality, magnetism, magnetoelectricity – three types of different phenomena. '
    'Whether they can be exhibited as joint effects, both in optics and microwaves? The goal of '
    'this session is to discuss such joint effects in metamaterial structures in a view of '
    'different aspects of the field-matter interaction.':
        'Chirality, magnetism and magnetoelectricity are three distinct phenomena. Can they '
        'appear as joint effects, in both optics and microwaves? This symposium discusses such '
        'joint effects in metamaterial structures, viewed through the different aspects of '
        'field–matter interaction.',
    # V — one stray article
    'has witnessed a remarkable growth in recent years':
        'has witnessed remarkable growth in recent years',
}

applied = []
for s in syms:
    fixed = []
    for d in s['desc']:
        for old, new in FIXES.items():
            if old in d:
                d = d.replace(old, new)
                applied.append((s['roman'], old[:56]))
        fixed.append(d)
    s['desc'] = fixed

print('corrections appliquées :')
for r, frag in applied:
    print('   %-4s %s…' % (r, frag))

# ---------------------------------------------------------------- assembly


def esc(x):
    return html.escape(x, quote=False)


def img_of(src):
    return 'images/chairs/' + src.rsplit('/', 1)[-1]


jump = '\n'.join(
    '      <a class="sym-jump reveal" href="#symposium-%d"><span class="sym-no">%s</span>'
    '<span>%s</span></a>' % (i + 1, s['roman'], esc(s['title']))
    for i, s in enumerate(syms))

blocks = []
for i, s in enumerate(syms):
    chairs_head = 'Symposium Chair' if len(s['chairs']) == 1 else 'Symposium Chairs'
    chairs = '\n'.join(
        '        <div class="chair-card reveal">'
        '<img class="chair-photo" src="%s" alt="%s" loading="lazy" width="76" height="76">'
        '<div class="chair-id"><strong>%s</strong><span>%s</span></div></div>'
        % (img_of(c['img']), esc(c['name']), esc(c['name']), esc(c['aff']))
        for c in s['chairs'])
    desc = '\n'.join('      <p class="sym-desc reveal">%s</p>' % esc(d) for d in s['desc'])
    chips = '\n'.join('        <span class="chip">%s</span>' % esc(t) for t in s['topics'])
    blocks.append('''<section%s id="symposium-%d">
  <div class="wrap">
    <p class="kicker reveal">Symposium %s</p>
    <h2 class="sec reveal">%s</h2>
%s
    <h3 class="sym-sub reveal">%s</h3>
    <div class="chair-grid">
%s
    </div>
    <h3 class="sym-sub reveal">Topics</h3>
    <div class="chip-list reveal">
%s
    </div>
    <h3 class="sym-sub reveal">Invited Speakers</h3>
    <p class="tba-line reveal">Invited speakers will be announced once confirmed.</p>
    <p class="back-top reveal"><a href="#overview">Back to symposia &uarr;</a></p>
  </div>
</section>''' % (' class="alt-band"' if i % 2 else '', i + 1, s['roman'], esc(s['title']),
                 desc, chairs_head, chairs, chips))

body = '''<section id="overview">
  <div class="wrap">
    <p class="kicker reveal">Program</p>
    <h2 class="sec reveal">Six focused symposia</h2>
    <p class="tlead reveal" style="margin-top:22px">The special symposia are a central scientific
      component of META 2027. Each is curated by leading researchers around one front of
      metamaterials and photonics, and runs inside the main program across the four days.</p>
    <div class="sym-nav">
%s
    </div>
  </div>
</section>

%s

<section%s>
  <div class="wrap" style="text-align:center;max-width:720px">
    <h2 class="sec reveal">Interested in organizing a focused session?</h2>
    <p class="tlead reveal" style="margin:16px auto 0">META also welcomes proposals for Special
      Sessions on emerging themes.</p>
    <div class="hero-cta reveal">
      <a class="btn btn-gold" href="special-sessions.html">Propose a Special Session &rarr;</a>
    </div>
  </div>
</section>''' % (jump, '\n\n'.join(blocks), ' class="alt-band"' if len(syms) % 2 else '')

s = open('symposia.html', encoding='utf-8').read()
start = s.index('</header>') + len('</header>')
end = s.index('<footer')
s = s[:start] + '\n\n' + body + '\n\n' + s[end:]

# a slightly more stately lead in the hero
s = re.sub(r'(<p class="lead">).*?(</p>)',
           lambda m: m.group(1) + 'Six symposia, each shaped by internationally recognized '
           'researchers, anchor the scientific program of META 2027.' + m.group(2),
           s, count=1, flags=re.S)
open('symposia.html', 'w', encoding='utf-8').write(s)
print('\nsymposia.html : %d octets' % len(s))
