import './FileLoader.js';
import './ThreeRendererElement.js';
import './ThreeGuiElement.js';

const loadObject = (count) => {
}

window.addEventListener("DOMContentLoaded", function() {
  var uploader = document.querySelector('file-loader');
  var renderer = document.querySelector('three-renderer');
  var gui = document.querySelector('three-gui');

  uploader.addEventListener('upload_complete', function(evt) {
    console.log(evt, evt.detail);
    renderer.setAttribute('src', `/stl/${evt.detail.filename.split('.')[0]}.stl`);
    gui.setElements(evt.detail.data);
  });

  gui.addEventListener('value-change', function(evt) {
    if(evt.detail) {
      var src = renderer.src;
      try {
        var url = new URL(src);
      } catch(e) {
        var url = new URL(window.location)
        url.pathname = src;
      }

      url.searchParams.set(evt.detail.property, evt.detail.value);

      console.log(url)
      renderer.src = url.href;
    }
  });
});
