import * as THREE from 'three';

export class World {
    constructor(scene) {
        this.scene = scene;
        this.colliders = [];
    }

    load() {
        // Standard lighting for horror
        const ambientLight = new THREE.AmbientLight(0x404040, 0.2); // Very dim ambient
        this.scene.add(ambientLight);

        // Floor
        const floorGeo = new THREE.PlaneGeometry(30, 30);
        const floorMat = new THREE.MeshStandardMaterial({
            color: 0x222222,
            roughness: 0.9
        });
        const floor = new THREE.Mesh(floorGeo, floorMat);
        floor.rotation.x = -Math.PI / 2;
        this.scene.add(floor);

        // Simple walls
        this.createWall(0, 2.5, -15, 30, 5); // Back
        this.createWall(0, 2.5, 15, 30, 5); // Front
        this.createWall(-15, 2.5, 0, 30, 5, true); // Left
        this.createWall(15, 2.5, 0, 30, 5, true); // Right

        // Add some "horror" pillars
        for (let i = 0; i < 8; i++) {
            const px = (Math.random() - 0.5) * 20;
            const pz = (Math.random() - 0.5) * 20;
            this.createPillar(px, 2.5, pz);
        }

        // Add a red object to find
        const target = new THREE.Mesh(
            new THREE.BoxGeometry(1, 1, 1),
            new THREE.MeshStandardMaterial({ color: 0x880000 })
        );
        target.position.set(5, 0.5, -5);
        this.scene.add(target);
        this.colliders.push(target);
    }

    createWall(x, y, z, width, height, rotate = false) {
        const geo = new THREE.BoxGeometry(width, height, 0.5);
        const mat = new THREE.MeshStandardMaterial({ color: 0x333333 });
        const wall = new THREE.Mesh(geo, mat);
        wall.position.set(x, y, z);
        if (rotate) wall.rotation.y = Math.PI / 2;
        this.scene.add(wall);
        this.colliders.push(wall);
    }

    createPillar(x, y, z) {
        const geo = new THREE.BoxGeometry(1, 5, 1);
        const mat = new THREE.MeshStandardMaterial({ color: 0x444444 });
        const pillar = new THREE.Mesh(geo, mat);
        pillar.position.set(x, y, z);
        this.scene.add(pillar);
        this.colliders.push(pillar);
    }
}
