from pathlib import Path
from zipfile import ZipFile, ZipInfo

out = Path(__file__).resolve().parent
svg = '''<svg xmlns="http://www.w3.org/2000/svg" width="360" height="100">
  <text x="10" y="28">Board at Gate 12.</text>
  <g style="display:none !important"><text x="10" y="54">Board at Gate 4.</text></g>
  <text x="10" y="80" style="display:none!important;display:inline!important">Departure 09:30.</text>
</svg>'''
html = '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Gate map</title></head><body>' + svg + '</body></html>'
(out / 'map.svg').write_text(svg)
(out / 'inline.xhtml').write_text(html)
with ZipFile(out / 'gates.epub', 'w') as book:
    for name, data in {
        'mimetype': 'application/epub+zip',
        'META-INF/container.xml': '<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0"><rootfiles><rootfile full-path="book.opf" media-type="application/oebps-package+xml"/></rootfiles></container>',
        'book.opf': '''<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="id">
          <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:identifier id="id">urn:example:gates</dc:identifier><dc:title>Gate Map</dc:title><dc:language>en</dc:language><meta property="dcterms:modified">2026-01-01T00:00:00Z</meta></metadata>
          <manifest><item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/><item id="inline" href="inline.xhtml" media-type="application/xhtml+xml" properties="svg"/><item id="map" href="map.svg" media-type="image/svg+xml"/></manifest>
          <spine><itemref idref="inline"/><itemref idref="map"/></spine></package>''',
        'nav.xhtml': '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head><title>Contents</title></head><body><nav epub:type="toc"><ol><li><a href="inline.xhtml">Inline map</a></li><li><a href="map.svg">Standalone map</a></li></ol></nav></body></html>',
        'inline.xhtml': html,
        'map.svg': svg,
    }.items():
        book.writestr(ZipInfo(name), data)
