import * as THREE from 'three';
import { state } from '../state.js';
import { SceneFeature } from './SceneFeature.js';
import sceneFeatureManager from './SceneFeatureManager.js';
import woodTextureUrl from '/textures/wood.png';

export class Stage extends SceneFeature {
    constructor() {
        super();
        sceneFeatureManager.register(this);
    }

    init() {
        // --- Dimensions from room-walls.js for positioning ---
        const length = 40;
        const naveWidth = 12;

        // --- Stage Properties ---
        const stageWidth = naveWidth - 1; // Slightly narrower than the nave
        const stageHeight = 1.5;
        const stageDepth = 5;

        // --- Material ---
        const woodTexture = state.loader.load(woodTextureUrl);
        woodTexture.wrapS = THREE.RepeatWrapping;
        woodTexture.wrapT = THREE.RepeatWrapping;
        woodTexture.repeat.set(stageWidth / 2, stageDepth / 2);
        const woodMaterial = new THREE.MeshStandardMaterial({
            map: woodTexture,
            roughness: 0.8,
            metalness: 0.1,
        });

        // --- Create Stage Mesh ---
        const stageGeo = new THREE.BoxGeometry(stageWidth, stageHeight, stageDepth);
        const stageMesh = new THREE.Mesh(stageGeo, woodMaterial);
        stageMesh.castShadow = true;
        stageMesh.receiveShadow = true;
        stageMesh.position.set(0, stageHeight / 2, -length / 2 + stageDepth / 2);
        state.scene.add(stageMesh);
    }
}

new Stage();