"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.groupDatasource = void 0;
var _locale = require("@mirai/locale");
var _Bookings = require("../Bookings.l10n");
const groupDatasource = function () {
  let dataSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  let search = arguments.length > 1 ? arguments[1] : undefined;
  if (!Array.isArray(dataSource)) return;
  const today = (0, _locale.UTC)(new Date());
  const value = {};
  dataSource.filter(item => search ? JSON.stringify(item).toLowerCase().includes(search.toLowerCase()) : true).forEach(item => {
    const {
      days
    } = (0, _locale.dateDiff)(today, (0, _locale.parseDate)(item.checkIn));
    const key = days >= 0 ? _Bookings.L10N.LABEL_NEXT_BOOKINGS.id : _Bookings.L10N.LABEL_PAST_BOOKINGS.id;
    value[key] = [...(value[key] || []), item];
  });
  return Object.keys(value).length ? value : undefined;
};
exports.groupDatasource = groupDatasource;
//# sourceMappingURL=groupDatasource.js.map