import { startParticleSketch, stopParticleSketch, startStartScreenSketch, stopStartScreenSketch } from "../p5_particles.js";

/**
 * Show game-over screen
 */
export function showGameOverScreen(state) {
    const canvasStage = document.querySelector(".canvas-stage");
    const p5GameOverPanel = document.getElementById("p5-game-over-panel");
    const renderCanvas = document.getElementById("renderCanvas");
    
    if (canvasStage) {
        canvasStage.hidden = true;
    }
    if (p5GameOverPanel) {
        p5GameOverPanel.hidden = false;
        const sketchContainer = document.getElementById("p5-sketch-container");
        if (sketchContainer) {
            startParticleSketch(sketchContainer);
        }
    }
    
    // Exit pointer lock
    if (document.pointerLockElement === renderCanvas && document.exitPointerLock) {
        document.exitPointerLock();
    }
    
    state.gameOverActive = true;
}

/**
 * Hide game-over screen
 */
export function hideGameOverScreen(state) {
    const canvasStage = document.querySelector(".canvas-stage");
    const p5GameOverPanel = document.getElementById("p5-game-over-panel");
    
    if (canvasStage) {
        canvasStage.hidden = false;
    }
    if (p5GameOverPanel) {
        p5GameOverPanel.hidden = true;
        stopParticleSketch();
    }
    
    state.gameOverActive = false;
}

/**
 * Show start screen
 */
export function showStartScreen(state) {
    const p5StartPanel = document.getElementById("p5-start-panel");
    
    if (p5StartPanel && !p5StartPanel.hidden) {
        const startContainer = document.getElementById("p5-start-container");
        if (startContainer) {
            startStartScreenSketch(startContainer);
        }
    }
}

/**
 * Hide start screen
 */
export function hideStartScreen(state) {
    const p5StartPanel = document.getElementById("p5-start-panel");
    
    if (p5StartPanel && !p5StartPanel.hidden) {
        p5StartPanel.hidden = true;
        stopStartScreenSketch();
    }
}
