"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getNextData = exports.getNextOrder = exports.sortData = exports.getSortingIcon = exports.DESCENDING = exports.ASCENDING = void 0;

var _react = _interopRequireDefault(require("react"));

var R = _interopRequireWildcard(require("ramda"));

var _ArrowDownIcon = _interopRequireDefault(require("mdi-react/ArrowDownIcon"));

var _ArrowUpIcon = _interopRequireDefault(require("mdi-react/ArrowUpIcon"));

var _sortingFunctionMap;

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var ASCENDING = 'ascending';
exports.ASCENDING = ASCENDING;
var DESCENDING = 'descending';
exports.DESCENDING = DESCENDING;

var getSortingIcon = function getSortingIcon(sortingOption, currentLabel) {
  var icon = null;

  if (sortingOption.order === ASCENDING) {
    icon = _react.default.createElement(_ArrowUpIcon.default, null);
  }

  if (sortingOption.order === DESCENDING) {
    icon = _react.default.createElement(_ArrowDownIcon.default, null);
  }

  if (sortingOption.label !== currentLabel) {
    icon = _react.default.createElement(_ArrowDownIcon.default, {
      className: "vs-unsorted-row-icon"
    });
  }

  return icon;
};

exports.getSortingIcon = getSortingIcon;

var sort = function sort(order) {
  return function (index, data) {
    return R.sortWith([order(R.path(["row", index]))])(data);
  };
};

var sortAscendingByIndex = sort(R.ascend);
var sortDescendingByIndex = sort(R.descend);
var sortingFunctionMap = (_sortingFunctionMap = {}, _defineProperty(_sortingFunctionMap, ASCENDING, sortAscendingByIndex), _defineProperty(_sortingFunctionMap, DESCENDING, sortDescendingByIndex), _sortingFunctionMap);

var sortData = function sortData(index, order, data) {
  return sortingFunctionMap[order](index, data);
};

exports.sortData = sortData;

var getNextOrder = function getNextOrder(order) {
  if (!order || order === ASCENDING) return DESCENDING;
  if (order === DESCENDING) return ASCENDING;
};

exports.getNextOrder = getNextOrder;

var getNextData = function getNextData(index, currentOrder, data) {
  return sortData(index, getNextOrder(currentOrder), data);
};

exports.getNextData = getNextData;