"use strict";

exports.__esModule = true;
exports.select = exports.includesString = exports.comparison = void 0;
var operators = {
  gt: function gt(a, b) {
    return a > b;
  },
  eq: function eq(a, b) {
    return a === b;
  },
  lt: function lt(a, b) {
    return a < b;
  },
  all: function all() {
    return true;
  }
};
var _comparison = exports.comparison = function comparison(row, columnId, value) {
  var filterValue = value[0],
    numberToCompareWith = value[1];
  var operator = filterValue.value;
  var rowValue = row.getValue(columnId);
  if (isNaN(numberToCompareWith) || numberToCompareWith === "") return true;
  var found = operators[operator](Number(rowValue), Number(numberToCompareWith));
  if (!found && row.subRows.length) return row.subRows.some(function (subRow) {
    return _comparison(subRow, columnId, value);
  });
  return found;
};
var multiSelect = function multiSelect(row, columnId, value) {
  var rowValue = row.getValue(columnId);
  if (value.length < 1) return true;
  return value.some(function (_ref) {
    var filterValue = _ref.value;
    if (filterValue === ("all" || "")) return true;
    return (filterValue == null || filterValue.toLowerCase == null ? void 0 : filterValue.toLowerCase()) === (rowValue == null || rowValue.toLowerCase == null ? void 0 : rowValue.toLowerCase());
  });
};
var singleSelect = function singleSelect(row, columnId, value) {
  var rowValue = row.getValue(columnId);
  var filterValue = value.value;
  if (filterValue === "all") return true;
  return (filterValue == null || filterValue.toLowerCase == null ? void 0 : filterValue.toLowerCase()) === (rowValue == null || rowValue.toLowerCase == null ? void 0 : rowValue.toLowerCase());
};
var select = exports.select = function select(row, columnId, value) {
  var isMulti = Array.isArray(value);
  var found = isMulti ? multiSelect(row, columnId, value) : singleSelect(row, columnId, value);
  if (!found && row.subRows.length) return row.subRows.some(function (subRow) {
    return isMulti ? multiSelect(subRow, columnId, value) : singleSelect(subRow, columnId, value);
  });
  return found;
};
var _includesString = exports.includesString = function includesString(row, columnId, value) {
  var _row$getValue;
  var rowValue = (_row$getValue = row.getValue(columnId)) == null || _row$getValue.toString == null ? void 0 : _row$getValue.toString();
  if (typeof rowValue !== "string") return false;
  var search = value ? value.toLowerCase() : "";
  var found = rowValue.toLowerCase().includes(search);
  if (!found && row.subRows.length) return row.subRows.some(function (subRow) {
    return _includesString(subRow, columnId, value);
  });
  return found;
};