'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _yogaLayout = require('yoga-layout');

var _yogaLayout2 = _interopRequireDefault(_yogaLayout);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var ALMOST_ZERO = 0.000001;

var Node = function () {
  function Node(root, props) {
    _classCallCheck(this, Node);

    this._top = null;
    this._left = null;
    this._width = null;
    this._heigth = null;
    this._padding = {};
    this._margin = {};

    this.layout = _yogaLayout2.default.Node.createDefault();
  }

  _createClass(Node, [{
    key: 'reset',
    value: function reset() {
      this.top = null;
      this.left = null;
      this.width = null;
      this.height = null;
      this.padding = {};
      this.margin = {};
    }
  }, {
    key: 'top',
    get: function get() {
      if (!this._top) {
        this._top = this.layout.getComputedLayout().top - this.marginTop;
      }

      return this._top;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._top = value;
    }
  }, {
    key: 'left',
    get: function get() {
      if (!this._left) {
        this._left = this.layout.getComputedLayout().left - this.marginLeft;
      }

      return this._left;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._left = value;
    }
  }, {
    key: 'width',
    get: function get() {
      if (!this._width) {
        this._width = this.layout.getComputedLayout().width + this.marginLeft + this.marginRight;
      }

      return this._width;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._width = value;
    }
  }, {
    key: 'height',
    get: function get() {
      if (!this._heigth) {
        this._heigth = this.layout.getComputedLayout().height + this.marginTop + this.marginBottom;
      }

      return this._heigth;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._heigth = value;
    }
  }, {
    key: 'paddingTop',
    get: function get() {
      if (!this._padding.top) {
        this._padding.top = this.layout.getComputedPadding(_yogaLayout2.default.EDGE_TOP);
      }

      return this._padding.top;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._padding.top = value;
    }
  }, {
    key: 'paddingRight',
    get: function get() {
      if (!this._padding.right) {
        this._padding.right = this.layout.getComputedPadding(_yogaLayout2.default.EDGE_RIGHT);
      }

      return this._padding.right;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._padding.right = value;
    }
  }, {
    key: 'paddingBottom',
    get: function get() {
      if (!this._padding.bottom) {
        this._padding.bottom = this.layout.getComputedPadding(_yogaLayout2.default.EDGE_BOTTOM);
      }

      return this._padding.bottom;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._padding.bottom = value;
    }
  }, {
    key: 'paddingLeft',
    get: function get() {
      if (!this._padding.left) {
        this._padding.left = this.layout.getComputedPadding(_yogaLayout2.default.EDGE_LEFT);
      }

      return this._padding.left;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._padding.left = value;
    }
  }, {
    key: 'marginTop',
    get: function get() {
      if (!this._margin.top) {
        this._margin.top = this.layout.getComputedMargin(_yogaLayout2.default.EDGE_TOP);
      }

      return this._margin.top;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._margin.top = value;
    }
  }, {
    key: 'marginRight',
    get: function get() {
      if (!this._margin.right) {
        this._margin.right = this.layout.getComputedMargin(_yogaLayout2.default.EDGE_RIGHT);
      }

      return this._margin.right;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._margin.right = value;
    }
  }, {
    key: 'marginBottom',
    get: function get() {
      if (!this._margin.bottom) {
        this._margin.bottom = this.layout.getComputedMargin(_yogaLayout2.default.EDGE_BOTTOM);
      }

      return this._margin.bottom;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._margin.bottom = value;
    }
  }, {
    key: 'marginLeft',
    get: function get() {
      if (!this._margin.left) {
        this._margin.left = this.layout.getComputedMargin(_yogaLayout2.default.EDGE_LEFT);
      }

      return this._margin.left;
    },
    set: function set(value) {
      if (value === 0) {
        value = ALMOST_ZERO;
      }

      this._margin.left = value;
    }
  }, {
    key: 'padding',
    get: function get() {
      return {
        top: this.paddingTop,
        right: this.paddingRight,
        bottom: this.paddingBottom,
        left: this.paddingLeft
      };
    },
    set: function set(value) {
      this._padding = value;
    }
  }, {
    key: 'margin',
    get: function get() {
      return {
        top: this.marginTop,
        right: this.marginRight,
        bottom: this.marginBottom,
        left: this.marginLeft
      };
    },
    set: function set(value) {
      this._margin = value;
    }
  }]);

  return Node;
}();

exports.default = Node;