var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/// <reference path="../../collection/List.ts" />
/// <reference path="../event/ProductAddToCartEvent.ts" />
/// <reference path="../event/ProductBuyEvent.ts" />
/// <reference path="../event/ProductViewEvent.ts" />
/// <reference path="../../serialization/ISerializable.ts" />
/// <reference path="./TrackingListener.ts" />
var econda;
(function (econda) {
    var recengine;
    (function (recengine) {
        var history;
        (function (history) {
            /**
             * History of visitor. The history is part of a visitor profile. See {@link econda.recengine.VisitorProfile}.
             * @class econda.recengine.history.VisitorHistory
             * @extends econda.collection.List
             * @author Christoph Luetjen
             */
            var VisitorHistory = (function (_super) {
                __extends(VisitorHistory, _super);
                function VisitorHistory() {
                    _super.apply(this, arguments);
                    /**
                     * Max number of events in history. Older events will be deleted.
                     * @cfg {Number} [maxLength=50]
                     */
                    this._maxLength = 30;
                }
                VisitorHistory.prototype.getMaxLength = function () {
                    return this._maxLength;
                };
                VisitorHistory.prototype.setMaxLength = function (maxLength) {
                    this._maxLength = +maxLength;
                };
                /**
                 * Remove outdated items
                 */
                VisitorHistory.prototype.cleanup = function () {
                    this.sort('timestamp');
                    if (this._items.length > this._maxLength) {
                        var numberOfItemsToRemove = this._items.length - this._maxLength;
                        this._items.splice(0, numberOfItemsToRemove);
                    }
                };
                VisitorHistory.prototype.getObjectData = function () {
                    return {
                        className: 'econda.recengine.history.VisitorHistory',
                        data: {
                            items: this._items
                        }
                    };
                };
                VisitorHistory.prototype.setObjectData = function (data) {
                    if (typeof data === 'object' && data !== null) {
                        if (typeof data.items !== 'undefined') {
                            this._items = data.items;
                        }
                    }
                };
                /**
                 * Overwrite empty collection changed callback.
                 */
                VisitorHistory.prototype._collectionChanged = function () {
                    this.cleanup();
                };
                return VisitorHistory;
            }(econda.collection.List));
            history.VisitorHistory = VisitorHistory; // end of class
        })(history = recengine.history || (recengine.history = {}));
    })(recengine = econda.recengine || (econda.recengine = {}));
})(econda || (econda = {})); // end of module