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

import {$famous} from '../service/famous';
// FaNode

@Component({
  selector: 'fa-node',
  properties: ['config',
               'mountpoint',
               'origin',
               'align',
               'position',
               'rotate',
               'scale',
               'sizemode',
               'absolutesize',
               'proportionalsize',
               'differentialsize',
               'opacity'],
  lifecycle: [onInit, onChange]
})

@View({
  template: ``
})

export class FaNode {

  node: Object;
  config: Object;
  component: Object;
  mountpoint: Array<number>[];
  origin: Array<number>[];
  align: Array<number>[];
  position: Array<number>[];
  rotate: Array<number>[];
  scale: Array<number>[];
  sizemode: Array<number>[];
  absolutesize: Array<number>[];
  proportionalsize: Array<number>[];
  differentialsize: Array<number>[];
  opacity: Number;

  constructor() {
    this.node = $famous.get().scene.addChild();
  }

  setMountPoint() {
    var n = this;
    this.node.setMountPoint(this.mountpoint[0], this.mountpoint[1], this.mountpoint[2]);
  }

  setOrigin() {
    var n = this;
    this.node.setOrigin(this.origin[0], this.origin[1], this.origin[2]);
  }

  setAlign() {
    var n = this;
    this.node.setAlign(this.align[0], this.align[1], this.align[2]);
  }

  setPosition() {
    this.node.setPosition(this.position[0], this.position[1], this.position[2]);
  }

  setRotation() {
    this.node.setRotation(this.rotate[0], this.rotate[1], this.rotate[2]);
  }

  setScale() {
    this.node.setScale(this.scale[0], this.scale[1], this.scale[2]);
  }

  setSizeMode() {
    this.node.setSizeMode(this.sizemode[0], this.sizemode[1], this.sizemode[2]);
  }

  setAbsoluteSize() {
    this.node.setAbsoluteSize(this.absolutesize[0], this.absolutesize[1], this.absolutesize[2]);
  }

  setProportionalSize() {
    this.node.setProportionalSize(this.proportionalsize[0], this.proportionalsize[1], this.proportionalsize[2]);
  }

  setDifferentialSize() {
    this.node.setDifferentialSize(this.differentialsize[0], this.differentialsize[1], this.differentialsize[2]);
  }

  setOpacity() {
    this.node.setOpacity(this.opacity);
  }

  onInit() {

      this.sizemode ? this.setSizeMode() : false;
      this.absolutesize ? this.setAbsoluteSize() : false;
      this.proportionalsize ? this.setProportionalSize() : false;
      this.differentialsize ? this.setDifferentialSize() : false;
      this.scale ? this.setScale() : false;
      this.mountpoint ? this.setMountPoint() : false;
      this.origin ? this.setOrigin() : false;
      this.align ? this.setAlign() : false;
      this.position ? this.setPosition() : false;
      this.rotate ? this.setRotation() : false;
      this.opacity ? this.setOpacity() : false;
      this.component = this.node.addComponent(this.config);

  }

  onChange(change) {
      change.sizemode ? this.setSizeMode() : false;
      change.absolutesize ? this.setAbsoluteSize() : false;
      change.proportionalsize ? this.setProportionalSize() : false;
      change.differentialsize ? this.setDifferentialSize() : false;
      change.scale ? this.setScale() : false;
      change.mountpoint ? this.setMountPoint() : false;
      change.origin ? this.setOrigin() : false;
      change.align ? this.setAlign() : false;
      change.position ? this.setPosition() : false;
      change.rotate ? this.setRotation() : false;
      change.opacity ? this.setOpacity() : false;
  }


}
