"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecordUpdates = void 0;
var react_1 = __importDefault(require("react"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var DeltaField_1 = require("./components/DeltaField");
var SegmentDeltaField_1 = require("./components/SegmentDeltaField");
var CollapsibleItemsContext_1 = require("../contexts/CollapsibleItemsContext");
var MoreItemsLink_1 = require("../MoreItemsLink");
var styles_1 = require("./styles");
var RecordUpdates = function (_a) {
    var updates = _a.updates, recordId = _a.recordId, isSegment = _a.isSegment;
    var styles = (0, styles_1.useStyles)();
    var _b = (0, CollapsibleItemsContext_1.useCollapsibleItems)({
        itemsId: recordId,
        items: updates
    }), onExpand = _b.onExpand, collapsedItemsCount = _b.collapsedItemsCount, itemsToShow = _b.itemsToShow;
    var DeltaFieldComponent = isSegment ? SegmentDeltaField_1.SegmentDeltaField : DeltaField_1.DeltaField;
    return (react_1.default.createElement(react_1.default.Fragment, null,
        itemsToShow.map(function (update, index) { return (react_1.default.createElement(DeltaFieldComponent, { key: index, delta: update })); }),
        collapsedItemsCount ? (react_1.default.createElement(MoreItemsLink_1.MoreItemsLink, { itemsCount: collapsedItemsCount, itemsLabel: collapsedItemsCount === 1 ? ui_i18n_1.default.text('update') : ui_i18n_1.default.text('updates'), onClick: onExpand, className: styles.moreLabel })) : null));
};
exports.RecordUpdates = RecordUpdates;
