"use strict";

var _lodash = _interopRequireDefault(require("lodash"));

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

var filter = {
  generateLayout: function generateLayout(data) {
    var layout = {
      wrows: [],
      worows: []
    }; // All Items

    var wrows = _lodash.default.clone(data); // Remove Without Rows


    var worows = _lodash.default.remove(wrows, function (item) {
      var isLayout = item.layout ? item.layout.row : item.layout;
      return isLayout === undefined;
    });

    layout.worows = worows; // Concat all items without rows
    // All row indices

    var rowIndex = _lodash.default.map(wrows, 'layout.row');

    var uniqIndex = _lodash.default.uniq(rowIndex);

    var sortedIndex = _lodash.default.sortBy(uniqIndex);

    _lodash.default.each(sortedIndex, function (value) {
      var rows = [];

      _lodash.default.each(wrows, function (item) {
        if (item.layout) {
          if (item.layout.row === value) {
            rows.push(item);
          }
        }
      });

      layout.wrows.push(rows);
    });

    return layout;
  }
};
module.exports = filter;