import * as THREE from 'three';
import { createVcrDisplay } from './vcr-display.js';

export function createVcr() {
    // Materials
    const vcrBodyMaterial = new THREE.MeshPhongMaterial({
        color: 0x222222, // Dark metallic gray
        shininess: 70,
        specular: 0x444444
    });
    const slotMaterial = new THREE.MeshPhongMaterial({
        color: 0x0a0a0a, // Deep black
        shininess: 5,
        specular: 0x111111
    });

    // VCR Body
    const vcrBodyGeometry = new THREE.BoxGeometry(1.0, 0.2, 0.7);
    const vcrBody = new THREE.Mesh(vcrBodyGeometry, vcrBodyMaterial);
    vcrBody.position.y = 0; // Centered
    vcrBody.castShadow = true;
    vcrBody.receiveShadow = true;
    
    // Cassette Slot / Front Face
    const slotGeometry = new THREE.BoxGeometry(0.9, 0.05, 0.01);
    const slotMesh = new THREE.Mesh(slotGeometry, slotMaterial);
    slotMesh.position.set(0, -0.05, 0.35 + 0.005); 
    slotMesh.castShadow = true;
    slotMesh.receiveShadow = true;

    // VCR Display
    const displayMesh = createVcrDisplay();
    displayMesh.position.z = 0.35 + 0.005; 
    displayMesh.position.x = 0.2; // Adjusted X for arrow
    displayMesh.position.y = 0.03; 

    // VCR Group
    const vcrGroup = new THREE.Group();
    vcrGroup.add(vcrBody, slotMesh, displayMesh);
    vcrGroup.position.set(0, 0.1, 0); // Position the whole VCR slightly above the floor
    
    // Light from the VCR display itself
    const vcrDisplayLight = new THREE.PointLight(0x00ff44, 0.03, 1.8);
    vcrDisplayLight.position.set(0.23, 0.03, 0.35 + 0.03);
    vcrDisplayLight.castShadow = true;
    vcrDisplayLight.shadow.mapSize.width = 256;
    vcrDisplayLight.shadow.mapSize.height = 256;
    vcrGroup.add(vcrDisplayLight);

    return vcrGroup;
}