import pygame
import json
import os
import random
import colorsys
import multiprocessing

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
POOL_FILE = os.path.join(BASE_DIR, "entropy", "qrng_pool.json")

def load_entropy_pool():
    """Load the entropy pool from qrng_pool.json."""
    if not os.path.exists(POOL_FILE):
        print("⚠️ No entropy pool found!")
        return []
    with open(POOL_FILE, 'r') as f:
        data = json.load(f)
        return data.get('pool', [])
    
def run_visualizer(mode="static"):
    print(f"Running mode: {mode}") 
    if mode == "static":
        from modes import static
        static.run()
    elif mode == "matrix_rain":
        from modes import matrix_rain
        matrix_rain.run()
    elif mode == "heatmap":
        from modes import heatmap
        heatmap.run()
    elif mode == "waveform":
        from modes import waveform
        waveform.run()
    elif mode == "wave":
        from modes import wave
        wave.run()
    #elif mode == "bell":
    #    from modes import bell
    #    bell.run()
    elif mode == "particles":
        from modes import particles
        particles.run()
    elif mode == "fireworks":
        from modes import fireworks
        fireworks.run()
    elif mode == "all":
        # Import all the necessary visualizers
        from modes import static, matrix_rain, heatmap, waveform, wave, particles, fireworks

        # Define processes for each visualizer
        processes = [
            multiprocessing.Process(target=static.run),
            multiprocessing.Process(target=matrix_rain.run),
            multiprocessing.Process(target=heatmap.run),
            multiprocessing.Process(target=waveform.run),
            multiprocessing.Process(target=wave.run),
            multiprocessing.Process(target=particles.run),
            multiprocessing.Process(target=fireworks.run),
            #multiprocessing.Process(target=bell.quantum_bells_loop)
        ]

        # Start all visualizers
        for p in processes:
            p.start()

        # Optionally: wait for them to finish
        for p in processes:
            p.join()
    else:
        print(f"Unknown mode: {mode}")

if __name__ == "__main__":
    run_visualizer("all")
