import * as BABYLON from "babylonjs";
import chestTextureUrl from "../../img/img_chest.png";
import wallTextureUrl from "../../img/img_wall.png";
import groundTextureUrl from "../../img/img_ground.png";
import doorTextureUrl from "../../img/img_door.png";

/**
 * Create floor material
 */
export function createFloorMaterial(scene, width, height) {
    const fm = new BABYLON.StandardMaterial('floorMat', scene);
    fm.specularColor = new BABYLON.Color3(0.1, 0.1, 0.1);
    fm.diffuseTexture = new BABYLON.Texture(groundTextureUrl, scene);
    fm.diffuseTexture.uScale = Math.max(1, Math.floor(width / 2));
    fm.diffuseTexture.vScale = Math.max(1, Math.floor(height / 2));
    fm.diffuseColor = new BABYLON.Color3(0.9, 0.9, 0.9);
    return fm;
}

/**
 * Create wall material
 */
export function createWallMaterial(scene) {
    const wallMat = new BABYLON.StandardMaterial('wallMat', scene);
    wallMat.diffuseTexture = new BABYLON.Texture(wallTextureUrl, scene);
    wallMat.diffuseColor = new BABYLON.Color3(0.95, 0.95, 0.95);
    return wallMat;
}

/**
 * Create chest material (normal or key variant)
 */
export function createChestMaterial(scene, isKey = false) {
    const mat = new BABYLON.StandardMaterial(`chestMat_${isKey ? 'key' : 'normal'}`, scene);
    mat.diffuseTexture = new BABYLON.Texture(chestTextureUrl, scene);
    mat.diffuseColor = new BABYLON.Color3(0.95, 0.95, 0.95);
    
    if (isKey) {
        mat.emissiveColor = new BABYLON.Color3(0.3, 0.22, 0.02);
    }
    
    return mat;
}

/**
 * Create exit door material
 */
export function createExitMaterial(scene) {
    const exitMat = new BABYLON.StandardMaterial('exitMat', scene);
    exitMat.diffuseTexture = new BABYLON.Texture(doorTextureUrl, scene);
    exitMat.diffuseColor = new BABYLON.Color3(0.95, 0.95, 0.95);
    exitMat.emissiveColor = new BABYLON.Color3(0.07, 0.07, 0.07);
    return exitMat;
}
