"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getItemKey = exports.isGroupItem = exports.flattenGroupedItems = exports.buildGroupedItems = void 0;
var ramda_1 = require("ramda");
var moment_1 = __importDefault(require("moment"));
var buildGroupedItem = function (_a) {
    var day = _a[0], children = _a[1];
    return ({
        timestamp: (0, moment_1.default)(day).valueOf(),
        collapsed: false,
        children: children
    });
};
var getDay = function (_a) {
    var timestamp = _a.timestamp;
    return (0, moment_1.default)(timestamp).startOf('day').format('YYYY-MM-DD');
};
exports.buildGroupedItems = (0, ramda_1.pipe)((0, ramda_1.groupBy)(getDay), ramda_1.toPairs, (0, ramda_1.map)(buildGroupedItem));
var chainIndexed = (0, ramda_1.addIndex)(ramda_1.chain);
exports.flattenGroupedItems = chainIndexed(function (_a, index) {
    var children = _a.children, collapsed = _a.collapsed, timestamp = _a.timestamp;
    var groupItem = { collapsed: collapsed, timestamp: timestamp, index: index };
    return collapsed ? [groupItem] : __spreadArray([groupItem], children, true);
});
exports.isGroupItem = (0, ramda_1.has)('collapsed');
var getItemKey = function (index, data) {
    var item = data[index];
    return 'uri' in item ? item.uri : "".concat(item.index);
};
exports.getItemKey = getItemKey;
