import { Controller } from '@hotwired/stimulus';
import UI from '../ui.js';
import BIM from '../bim.js';

/*
 * This is an example Stimulus controller!
 *
 * Any element with a data-controller="hello" attribute will cause
 * this controller to be executed. The name "hello" comes from the filename:
 * hello_controller.js -> "hello"
 *
 * Delete this file or adapt it for your use!
 */
export default class extends Controller {
    static targets = ['scene'];

    connect() {
    }

    /**
     * 
     * @param {Element} container 
     */
    sceneTargetConnected(container) {
        UI.setScene(container);
        const model = UI.ifcLoader(container);
        container.ondblclick = () => BIM.activateClipper();
        container.onkeydown = event => {
            console.log(event);
            if (event.code === 'Delete' || event.code === 'Backspace') {
                BIM.deleteClipper();
            }
        }
    }

    /**
     * 
     * @param {Event} event 
     */
    keyboard(event) {
        console.log(event);
    }
}