#!/usr/bin/env python3
"""Check PWA global name state + ortuzar gap."""
import re, json
from pathlib import Path

h = Path("/Users/brians/Documents/AveryArt/avery_pwa.html").read_text()
map_refs = len(re.findall(r"\bMAP_DATA\b", h))
drill_refs = len(re.findall(r"\bDRILL_DATA\b", h))
pipe_refs = len(re.findall(r"\bPIPELINE_DATA\b", h))
stub_defs = len(re.findall(r"const __MAP_JSON__ = ", h))

has_map_def = "const MAP_DATA = " in h
has_drill_def = "const DRILL_DATA = " in h
has_pipe_def = "const PIPELINE_DATA = " in h

print(f"MAP_DATA refs in code: {map_refs}")
print(f"DRILL_DATA refs in code: {drill_refs}")
print(f"PIPELINE_DATA refs in code: {pipe_refs}")
print(f"__MAP_JSON__ stub defs: {stub_defs}")
print(f"const MAP_DATA = defined: {has_map_def}")
print(f"const DRILL_DATA = defined: {has_drill_def}")
print(f"const PIPELINE_DATA = defined: {has_pipe_def}")
print(f"\nRESULT: {'PWA globals OK' if (has_map_def and has_drill_def and has_pipe_def) else 'PWA WOULD FAIL — global name mismatch'}")

print("\n--- ortuzar gap ---")
d = json.loads(Path("/Users/brians/Documents/AveryArt/map_data.json").read_text())
ortuzar = [g for g in d["galleries"] if g["gallery_id"] == "ortuzar"]
print(f"ortuzar in map_data: {len(ortuzar)} {'✓' if ortuzar else 'MISSING — add to GALLERY_COORDS in gallery_map_data.py'}")
if ortuzar:
    print(f"  name: {ortuzar[0]['name']}, pin: {ortuzar[0]['pin_style']}")
