"""Plot iso-classes 25 and 183 at n=10 (the two unreachable iso-classes)."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import networkx as nx
import matplotlib.pyplot as plt
from collections import Counter
from triangulation_gen import enumerate_all_triangulations


isos = enumerate_all_triangulations(10)
targets = [25, 183]

fig, axes = plt.subplots(1, 2, figsize=(14, 7))
for ax, idx in zip(axes, targets):
    T = isos[idx]
    ip, emb = nx.check_planarity(T)
    pos = nx.combinatorial_embedding_to_pos(emb)
    nx.draw_networkx_edges(T, pos, ax=ax, edge_color='black', width=1.0)
    nx.draw_networkx_nodes(T, pos, ax=ax, node_color='lightblue',
                            node_size=380, edgecolors='black')
    nx.draw_networkx_labels(T, pos, ax=ax, font_size=10)
    ds = sorted([T.degree(v) for v in T.nodes()], reverse=True)
    dcounts = Counter(ds)
    ds_str = ", ".join(f"{d}^{c}" if c > 1 else str(d)
                       for d, c in sorted(dcounts.items(), reverse=True))
    ax.set_title(f"n=10 iso-class {idx}\n"
                 f"degree sequence: {ds_str}\n"
                 f"min degree: {min(ds)}, max: {max(ds)}",
                 fontsize=11)
    ax.set_aspect('equal')
    ax.axis('off')

plt.tight_layout()
out = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                    '..', 'unreached_iso_n10.png')
plt.savefig(out, dpi=130, bbox_inches='tight')
print(f"saved: {out}")

# Also print structural details
print(f"\niso 25 edges: {sorted(isos[25].edges())}")
print(f"iso 183 edges: {sorted(isos[183].edges())}")
print(f"\niso 25 degree seq: {sorted([isos[25].degree(v) for v in isos[25].nodes()], reverse=True)}")
print(f"iso 183 degree seq: {sorted([isos[183].degree(v) for v in isos[183].nodes()], reverse=True)}")
