'use strict';

var HomeCtrl = ['$scope', '$location', 'messages', 'Message', function ($scope, $location, messages, Message) {
    $scope.chosen = messages.Type;
    $scope.info = messages.Threads;
    $scope.tags = messages.Tags
    $scope.getMessages = function (type) {
        Message.query({type: type}, function (result) {
            $scope.info = result.Threads;
            $scope.tags = result.Tags;
            $scope.chosen = result.Type;
        });
    }
    $scope.getTags = function (tag) {
        Message.query({type: $scope.Type, tag: tag}, function (result) {
            $scope.info = result.Threads;
            $scope.tags = result.Tags;
            $scope.chosen = result.Type;
        });
    }
}];
HomeCtrl.resolve = {
    messages: ['$q', '$route', 'Message', function ($q, $route, Message) {
        var deferred = $q.defer();

        var successCb = function (result) {
            deferred.resolve(result);
        };

        Message.query({type: 'open'}, successCb);
        return deferred.promise;
    }]
};