'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 _Item = require('./Item');

var _Item2 = _interopRequireDefault(_Item);

var _lodash = require('lodash');

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

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

var CHUNKS = 4;

var TexturesGrid = function (_Component) {
  _inherits(TexturesGrid, _Component);

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

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

  _createClass(TexturesGrid, [{
    key: 'render',
    value: function render() {
      var _this2 = this;

      // Filtered textures
      var filteredRows = [];

      this.props.textures.forEach(function (texture) {

        // Push filtered text only
        if (texture.name.toLowerCase().indexOf(_this2.props.filterText.toLowerCase()) !== -1 || _this2.props.tag.toLowerCase().indexOf(_this2.props.filterText.toLowerCase()) !== -1) {
          filteredRows.push(texture);
        }
      });

      // Chunk textures array
      var rows = (0, _lodash.chunk)(filteredRows, CHUNKS);
      var reactRows = [];
      var rowKey = 0;

      rows.forEach(function (row) {
        var reactCol = [];

        row.forEach(function (col) {
          reactCol.push(_react2.default.createElement(_Item2.default, {
            key: col.id,
            texture: col,
            name: col.name,
            path: col.path,
            selected: col.path in _this2.props.selectedTextures,
            setFooterText: _this2.props.setFooterText,
            onTexturePreview: _this2.props.onTexturePreview,
            copyToClipboard: _this2.props.copyToClipboard,
            selectTexture: _this2.props.selectTexture,
            deselectTexture: _this2.props.deselectTexture,
            openDesktopViewer: _this2.props.openDesktopViewer }));
        });

        reactRows.push(_react2.default.createElement(
          'div',
          { key: rowKey++, className: 'row', style: rowStyle },
          reactCol
        ));
      });

      // Hide grid if no data
      var content = null;
      if (filteredRows.length > 0) {
        content = _react2.default.createElement(
          'div',
          { className: 'container-fluid', style: gridStyle },
          _react2.default.createElement(
            'div',
            { style: tagStyle },
            this.props.tag
          ),
          reactRows
        );
      }

      return _react2.default.createElement(
        'div',
        null,
        content
      );
    }
  }]);

  return TexturesGrid;
}(_react.Component);

exports.default = TexturesGrid;


var gridStyle = {
  marginTop: '40px'
};

var rowStyle = {
  marginBottom: '20px'
};

var tagStyle = {
  marginBottom: '20px',
  fontSize: '12px',
  color: '#a1a1a1'
};