'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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _export = require('./export');

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"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

// export default function Layer({ layer, scene, catalog }) {
var Layer = function (_Component) {
  _inherits(Layer, _Component);

  function Layer() {
    _classCallCheck(this, Layer);

    return _possibleConstructorReturn(this, (Layer.__proto__ || Object.getPrototypeOf(Layer)).apply(this, arguments));
  }

  _createClass(Layer, [{
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps() {
      var _props = this.props,
          layer = _props.layer,
          scene = _props.scene,
          catalog = _props.catalog;
      var unit = scene.unit,
          groups = scene.groups;
      var lines = layer.lines,
          areas = layer.areas,
          vertices = layer.vertices,
          holes = layer.holes,
          layerID = layer.id,
          items = layer.items,
          opacity = layer.opacity,
          visibleItems = layer.visibleItems;
      // console.log("items : ", items)

      items.valueSeq().map(function (item) {
        return console.log("item : ", item);
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _props2 = this.props,
          layer = _props2.layer,
          scene = _props2.scene,
          catalog = _props2.catalog;
      var unit = scene.unit,
          groups = scene.groups;
      var lines = layer.lines,
          areas = layer.areas,
          vertices = layer.vertices,
          holes = layer.holes,
          layerID = layer.id,
          items = layer.items,
          opacity = layer.opacity,
          visibleItems = layer.visibleItems;


      return _react2.default.createElement(
        'g',
        { opacity: opacity },
        areas.valueSeq().filter(function (i) {
          return !visibleItems[i.id];
        }).map(function (area) {
          return _react2.default.createElement(_export.Area, { key: area.id, layer: layer, area: area, unit: unit, catalog: catalog });
        }),
        lines.valueSeq().filter(function (i) {
          return !visibleItems[i.id];
        }).map(function (line) {
          return _react2.default.createElement(_export.Line, { key: line.id, layer: layer, line: line, scene: scene, catalog: catalog });
        }),
        items.valueSeq().filter(function (i) {
          return !visibleItems[i.id] && i.name == "Floorplan";
        }).map(function (item) {
          return _react2.default.createElement(_export.Item, { key: item.id, layer: layer, item: item, scene: scene, catalog: catalog });
        }),
        items.valueSeq().filter(function (i) {
          return !visibleItems[i.id] && i.name != "Floorplan";
        }).map(function (item) {
          return _react2.default.createElement(_export.Item, { key: item.id, layer: layer, item: item, scene: scene, catalog: catalog });
        }),
        vertices.valueSeq().filter(function (v) {
          return v.selected;
        }).map(function (vertex) {
          return _react2.default.createElement(_export.Vertex, { key: vertex.id, layer: layer, vertex: vertex });
        }),
        groups.valueSeq().filter(function (g) {
          return g.hasIn(['elements', layerID]) && g.get('selected');
        }).map(function (group) {
          return _react2.default.createElement(_export.Group, { key: group.get('id'), layer: layer, group: group, scene: scene, catalog: catalog });
        })
      );
    }
  }]);

  return Layer;
}(_react.Component);

exports.default = Layer;


Layer.propTypes = {
  layer: _propTypes2.default.object.isRequired,
  scene: _propTypes2.default.object.isRequired,
  catalog: _propTypes2.default.object.isRequired
};