'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
var byColumn = function byColumn(sortingColumns, selectedColumn) {
  var sortingColumn = sortingColumns && sortingColumns.length ? sortingColumns[0] : {};
  var sort = 'asc';

  if (sortingColumn.property === selectedColumn) {
    sort = sortingColumn.sort === 'asc' ? 'desc' : 'asc';
  }

  return [{
    property: selectedColumn,
    sort: sort
  }];
};

// sorter === lodash orderBy
// https://lodash.com/docs#orderBy
byColumn.sort = function (data, columns, sorter) {
  if (!columns) {
    return data;
  }
  var column = columns[0]; // Sort based on the first one

  if (!column || !column.property || !column.sort) {
    return data;
  }

  return sorter(data, [column.property], [column.sort]);
};

exports.default = byColumn;