class DashboardsController extends EICController {

    constructor(params) {
        super(params)
        this.arenaConfig = app.Assets.Store.json.arenaConfig
        this.agentDefs = app.Assets.Store.json.agentDefs
        this.eventsMapping = app.Assets.Store.json.eventsMapping
    }



    /**
     * 
     * @returns 
     */
    spaceViewer() {
        const models = {
        }

        const ttb = new app.LoadedModules.Threetobus({
            eventsMapping: this.eventsMapping,
            sceneSize: this.arenaConfig.arenaSize,
        })
        ttb.initScene({
            axes: true,
            grid: true,
        })

        const m1 = ttb.agentFromJSON('agent42', this.agentDefs.molecule1)
        ttb.scene.add(m1)

        //TODO: eventsMapping: address child by suffix in assignations


        this.loadWindow(
            'visualisers/SpaceView', 
            {
                title: '3D view', 
                static: true,
                expanded: false,
                withSettings: true,
                windowStyle: this._boxFromPrefs('live.spaceview.3D', { x: 50, y:100, w:600, h:400 }),
            },
            {
                models: models,
                agentDefs: this.agentDefs,
                rendererId:'3drenderer',
                mode: '3D',
                ttb: ttb,
            }
        ) 


        this.loadWindow(
            'visualisers/SpaceView', 
            {
                title: '2D View', 
                static: true,
                expanded: false,
                withSettings: true,
                windowStyle: this._boxFromPrefs('live.spaceview.2D', { x: 500, y:100, w:600, h:400 }),
            },
            {
                models: models,
                agentDefs: this.agentDefs,
                rendererId:'2drenderer',
                mode: '2D',
                ttb: ttb,
            }
        )         
    }

    _boxFromPrefs(viewName, defaults){
        function getPref(path) {
            return path.split('.').reduce(
                (acc, key) => acc?.[key],
                app.User.preferences.windows
            )
        }
        const box = getPref(viewName)
console.log('====>',box, viewName)        
        let left = box.x ? box.x : defaults.x
        let top = box.y ? box.y : defaults.y
        let width = box.w ? box.w : defaults.w
        let height = box.x ? box.h : defaults.h
        return({
                    width: `${width}px`,
                    height: `${height}px`,
                    left: `${left}px`,
                    top: `${top}px`,
        })
    }
}

app.registerClass('DashboardsController', DashboardsController);