/**
 * ALGA ARENA — Arena Core Module
 * Builds the geometric crystalline core and outer orbits
 */

'use strict';

window.CinematicCore = (() => {
    let coreGroup, centralCore, innerCore, outerRings = [];

    const init = (scene) => {
        coreGroup = new THREE.Group();
        scene.add(coreGroup);

        // Glass physical material properties
        const coreMat = new THREE.MeshPhysicalMaterial({
            color: 0x00d4ff,
            emissive: 0x003366,
            roughness: 0.1,
            metalness: 0.1,
            transmission: 0.9,
            thickness: 1.2,
            ior: 1.5,
            transparent: true,
            opacity: 0.95,
            flatShading: true
        });

        // 1. Crystal core
        const coreGeo = new THREE.IcosahedronGeometry(1.2, 0);
        centralCore = new THREE.Mesh(coreGeo, coreMat);
        coreGroup.add(centralCore);

        // 2. Glowing center
        const innerGeo = new THREE.IcosahedronGeometry(0.5, 0);
        const innerMat = new THREE.MeshBasicMaterial({
            color: 0xffffff,
            transparent: true,
            opacity: 0.8
        });
        innerCore = new THREE.Mesh(innerGeo, innerMat);
        coreGroup.add(innerCore);

        // 3. Concentration rings
        const ringMat = new THREE.MeshStandardMaterial({
            color: 0x10121d,
            metalness: 0.95,
            roughness: 0.15,
            flatShading: true
        });

        const r1 = new THREE.Mesh(new THREE.TorusGeometry(2.0, 0.06, 8, 64), ringMat);
        r1.rotation.y = Math.PI / 4;
        coreGroup.add(r1);
        outerRings.push(r1);

        const r2 = new THREE.Mesh(new THREE.TorusGeometry(2.3, 0.05, 8, 64), ringMat);
        r2.rotation.x = Math.PI / 2;
        coreGroup.add(r2);
        outerRings.push(r2);
    };

    const update = (delta, time) => {
        if (!coreGroup) return;
        coreGroup.rotation.y += 0.05 * delta;
        if (centralCore) {
            centralCore.rotation.x += 0.08 * delta;
            centralCore.rotation.y += 0.12 * delta;
        }
    };

    const getCoreGroup = () => coreGroup;
    const getCentralCore = () => centralCore;
    const getOuterRings = () => outerRings;

    return { init, update, getCoreGroup, getCentralCore, getOuterRings };
})();
