import * as THREE from 'three';

export let state = undefined;

export function initState() {
    let config = {
        torchesEnabled: true,
        lasersEnabled: true,
        sideScreensEnabled: true,
        consoleRGBEnabled: true,
        consoleEnabled: true,
        gameboyEnabled: false,
        lightBarsEnabled: true,
        laserColorMode: 'RUNNING', // 'SINGLE', 'RANDOM', 'RUNNING', 'ANY'
        lightBarColors: ['#ff00ff', '#00ffff', '#ffff00'], // Default neon colors
        guestCount: 150,
        blackout: false,
        djHat: 'None', // 'None', 'Santa', 'Top Hat'
        debugPanelEnabled: false,
        visualizerType: 'Classic Wave',
        visualizerSeed: Math.random() * 1000
    };
    try {
        const saved = localStorage.getItem('partyConfig');
        if (saved) config = { ...config, ...JSON.parse(saved) };
    } catch (e) { console.warn('Error loading config', e); }

    state = {
    // Core Three.js components
    scene: null,
    camera: null,
    renderer: null,
    clock: new THREE.Clock(),
    composer: null,
    ssaoPass: null,
    tvScreen: null,
    tvScreenPowered: false,
    videoTexture: null,
    screenLight: null, // Light from the crystal ball
    candleLight: null, // Light from the candle
    effectsManager: null,
    screenEffect: {
        active: false,
        type: 0,
        startTime: 0,
        duration: 1000, // in ms
        onComplete: null,
        easing: (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t, // easeInOutQuad
    },


    // Video Playback
    isVideoLoaded: false,
    videoUrls: [],
    videoFilenames: [],
    currentVideoIndex: -1,
    posterImage: null,

    // Scene constants
    originalLampIntensity: 0.3,
    originalScreenIntensity: 0.2,
    screenIntensityPulse: 0.2,
    roomSize: 5,
    roomHeight: 3,
    debugLight: false, // Turn on light helpers
    debugCamera: false, // Turn on camera helpers
    partyStarted: false,
    blackoutMode: false,

    // Feature Configuration
    config: config,

    // DOM Elements
    container: document.body,
    videoElement: document.getElementById('video'),
    fileInput: document.getElementById('fileInput'),
    loadTapeButton: document.getElementById('loadTapeButton'),

    // Utilities
    loader: new THREE.TextureLoader(),
    pictureFrames: [],
    raycaster: new THREE.Raycaster(),
    seed: 12345,
    };

}
