import * as THREE from 'three';
import { state } from '../state.js';
import floorTextureUrl from '/textures/floor.png';
import sceneFeatureManager from './SceneFeatureManager.js';
import { initVideoUI } from '../core/video-player.js';
// Scene Features registered here:
import { CameraManager } from './camera-manager.js';
import { LightBall } from './light-ball.js';
import { Stage } from './stage.js';
import { PartyGuests } from './party-guests.js';
import { StageTorches } from './stage-torches.js';
import { MusicVisualizer } from './music-visualizer.js';
import { MusicPlayer } from './music-player.js';
import { WallCurtain } from './wall-curtain.js';
import { ReproWall } from './repro-wall.js';
import { StageLights } from './stage-lights.js';
import { MusicConsole } from './music-console.js';
import { DJ } from './dj.js';
import { ProjectionScreen } from './projection-screen.js';
import { StageLasers } from './stage-lasers.js';
import { ConfigUI } from './config-ui.js';
import { StageLightBars } from './stage-light-bars.js';
import { DebugPanel } from './fps-counter.js';
// Scene Features ^^^

// --- Scene Modeling Function ---
export function createSceneObjects() {
    new ConfigUI();
    sceneFeatureManager.init();
    initVideoUI();

    // --- Materials (MeshPhongMaterial) ---
    
    // --- 1. Floor --- (Resized to match the new cathedral dimensions)
    const floorWidth = 30;
    const floorLength = 50;
    const floorGeometry = new THREE.PlaneGeometry(floorWidth, floorLength);
    const floorTexture = state.loader.load(floorTextureUrl);
    floorTexture.wrapS = THREE.RepeatWrapping;
    floorTexture.wrapT = THREE.RepeatWrapping;
    floorTexture.repeat.set(floorWidth / 5, floorLength / 5); // Adjust texture repeat for new size
    const floorMaterial = new THREE.MeshPhongMaterial({ map: floorTexture, color: 0x666666, shininess: 5 }); 
    const floor = new THREE.Mesh(floorGeometry, floorMaterial);
    floor.rotation.x = -Math.PI / 2;
    floor.position.y = 0;
    floor.receiveShadow = true; 
    state.scene.add(floor);

    // 3. Lighting (Minimal and focused)
    const ambientLight = new THREE.AmbientLight(0x606060, 1.0); // Increased ambient light for a larger space
    state.scene.add(ambientLight);

    // Add a HemisphereLight for more natural, general illumination in a large space.
    const hemisphereLight = new THREE.HemisphereLight(0xffddcc, 0x444455, 0.5);

    // Visual aids for the light source positions
    if (state.debugLight && THREE.HemisphereLightHelper) {
        // Lamp Helper will now work since lampLight is added to the scene
        const hemisphereLightHelper = new THREE.HemisphereLightHelper(hemisphereLight, 0.1, 0x00ff00); // Green for lamp
        state.scene.add(hemisphereLightHelper);
    }

    state.scene.add(hemisphereLight);

    // Add fog for depth and atmosphere
    const fogColor = 0x040409;
    state.scene.fog = new THREE.FogExp2(fogColor, 0.04);
    state.scene.background = new THREE.Color(fogColor);
}
