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));
};
import { addIndex, chain, groupBy, has, map, pipe, toPairs } from 'ramda';
import moment from 'moment';
var buildGroupedItem = function (_a) {
    var day = _a[0], children = _a[1];
    return ({
        timestamp: moment(day).valueOf(),
        collapsed: false,
        children: children
    });
};
var getDay = function (_a) {
    var timestamp = _a.timestamp;
    return moment(timestamp).startOf('day').format('YYYY-MM-DD');
};
export var buildGroupedItems = pipe(groupBy(getDay), toPairs, map(buildGroupedItem));
var chainIndexed = addIndex(chain);
export var 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);
});
export var isGroupItem = has('collapsed');
export var getItemKey = function (index, data) {
    var item = data[index];
    return 'uri' in item ? item.uri : "".concat(item.index);
};
