"use strict";
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 __());
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require("@angular/core");
var static_1 = require("@angular/upgrade/static");
var angular = require("angular");
var _ = require("lodash");
var moment = require("moment");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __array = typescript_angular_utilities_1.services.array;
var __date = typescript_angular_utilities_1.services.date;
exports.moduleName = 'MessageLogTestModule';
var MessageLogTestController = (function () {
    function MessageLogTestController($q) {
        this.$q = $q;
    }
    MessageLogTestController.prototype.$onInit = function () {
        var _this = this;
        this.messages = _.times(20, this.generateMessage.bind(this));
        this.messageService = {
            updateMessage: function (message) {
                console.log('update ' + message.message);
                return _this.$q.when();
            },
            saveMessage: function (message) {
                message.createdBy = _this.generateAuthor();
                message.createdDate = __date.dateUtility.getNow();
                console.log('save ' + message.message);
                _this.messages.unshift(message);
                return _this.$q.when();
            },
            getMessages: function (startFrom, quantity) {
                var messageList = _.chain(_this.messages).drop(startFrom).take(quantity).value();
                var result = {
                    hasMoreMessages: startFrom + quantity < _this.messages.length,
                    messages: messageList,
                };
                return _this.$q.when(result);
            },
            deleteMessage: function (message) {
                console.log('delete ' + message.message);
                __array.arrayUtility.remove(_this.messages, message);
                return _this.$q.when();
            },
        };
    };
    MessageLogTestController.prototype.generateMessage = function (index) {
        var millisecondsAgo = index * 5000;
        var milliseconds = moment().milliseconds() - millisecondsAgo;
        var timestamp = moment(milliseconds).tz('US/Eastern');
        var message = {
            message: 'Message ' + index,
            createdBy: this.generateAuthor(),
            createdDate: timestamp,
            lastUpdatedBy: this.generateAuthor(),
            lastUpdatedDate: timestamp,
            edited: true,
        };
        return message;
    };
    MessageLogTestController.prototype.generateAuthor = function () {
        var authors = [
            { id: 1, name: 'Josh Graber' },
            { id: 2, name: 'Dude McKelly' },
            { id: 3, name: 'Micky Matson' },
            { id: 4, name: 'John Doe' },
            { id: 5, name: 'Abraham Lincoln' },
            { id: 6, name: 'Harrison Ford' },
            { id: 7, name: 'Han Solo' },
        ];
        var randomAuthor = Math.floor(Math.random() * authors.length);
        return authors[randomAuthor];
    };
    return MessageLogTestController;
}());
MessageLogTestController.$inject = ['$q'];
var MessageLogNg1BootstrapperComponent = (function () {
    function MessageLogNg1BootstrapperComponent() {
    }
    return MessageLogNg1BootstrapperComponent;
}());
MessageLogNg1BootstrapperComponent = __decorate([
    core_1.Component({
        selector: 'tsMessageLogNg1Bootstrapper',
        template: '<tsMessageLogNg1></tsMessageLogNg1>'
    })
], MessageLogNg1BootstrapperComponent);
exports.MessageLogNg1BootstrapperComponent = MessageLogNg1BootstrapperComponent;
var MessageLogNg1Directive = (function (_super) {
    __extends(MessageLogNg1Directive, _super);
    function MessageLogNg1Directive(elementRef, injector) {
        return _super.call(this, 'tsMessageLogNg1', elementRef, injector) || this;
    }
    return MessageLogNg1Directive;
}(static_1.UpgradeComponent));
MessageLogNg1Directive = __decorate([
    core_1.Directive({
        selector: 'tsMessageLogNg1'
    }),
    __metadata("design:paramtypes", [core_1.ElementRef, core_1.Injector])
], MessageLogNg1Directive);
exports.MessageLogNg1Directive = MessageLogNg1Directive;
angular.module(exports.moduleName, [])
    .component('tsMessageLogNg1', {
    template: require('./messageLogTest.html'),
    controller: 'MessageLogTestController',
    controllerAs: 'messageLog',
})
    .controller('MessageLogTestController', MessageLogTestController);
//# sourceMappingURL=data:application/json;base64, 