import * as THREE from 'three';
import { state } from '../state.js';
import floorTextureUrl from '/textures/stone_floor.png';
import sceneFeatureManager from './SceneFeatureManager.js';
// Scene Features registered here:
import { CameraManager } from './camera-manager.js';
import { RoomWalls } from './room-walls.js';
import { LightBall } from './light-ball.js';
import { Pews } from './pews.js';
import { Stage } from './stage.js';
import { MedievalMusicians } from './medieval-musicians.js';
import { PartyGuests } from './party-guests.js';
import { StageTorches } from './stage-torches.js';
import { Dancers } from './dancers.js';
import { MusicVisualizer } from './music-visualizer.js';
import { RoseWindowLight } from './rose-window-light.js';
import { RoseWindowLightshafts } from './rose-window-lightshafts.js';
import { StainedGlass } from './stained-glass-window.js';
import { MusicPlayer } from './music-player.js';
import { WallCurtain } from './wall-curtain.js';
// Scene Features ^^^

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

    // --- Materials (MeshPhongMaterial) ---
    
    // --- 1. Floor --- (Resized to match the new cathedral dimensions)
    const floorWidth = 24;
    const floorLength = 40;
    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 / 2, floorLength / 2); // Adjust texture repeat for new size
    const floorMaterial = new THREE.MeshPhongMaterial({ map: floorTexture, color: 0xaaaaaa, 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, 0.2); // 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);
}
