import {
Component,
View,
Parent,
onInit
} from 'angular2/angular2';

import {FaNode} from '../core/node';

// FaMesh

@Component({
  selector: 'fa-mesh',
  properties: ['geometry', 'color', 'detail'],
  lifecycle: [onInit]
})

@View({
  template: ``
})

export class FaMesh {
  mesh: Object;
  geometry: String;
  color: String;
  detail: Number;
  constructor(@Parent() parent:FaNode) {

    var Mesh = famous.webglRenderables.Mesh;
    this.mesh = new Mesh(parent.node);


  }
  onInit() {

    var Color = famous.utilities.Color;

    if(this.detail && this.geometry){
       console.log(this.geometry, this.detail);
       this.mesh.setGeometry(this.geometry, { detail: this.detail });
           console.log(this.mesh);
    } else if (this.geometry) {
       this.mesh.setGeometry(this.geometry);
    }

    this.color ? this.mesh.setBaseColor(new Color(this.color)) : this.mesh.setBaseColor(new Color('#ABABAB'));

  }
}
