'use strict';

define(['app'], function(app) {
	app.controller('RestCtrl', ['$http', '$scope', '$routeParams',
        function($http, $scope, $routeParams) {
        $scope.categories = [];

        $scope.getFeed = function(_jsonPath){


            $http({
                method: 'GET', 
                url: globals.RootPath + '/' + _jsonPath + '?store_category=' + $routeParams.storeCatID
            })

            .success(function(res, status){               
                if (status !== 200) return false;

                $scope.categories = [];

                for (var i=0; i<res.data.length; i++) {
                    var category = res.data[i];
                    // var catClass = '';
                    // switch (news.category) {
                    //     case 'Dešavanja':
                    //         catClass = 'events';
                    //     break;

                    //     case 'Aktuelno':
                    //         catClass = 'current';
                    //     break;

                    //     case 'Blog':
                    //         catClass = 'blog';
                    //     break;

                    //     case 'Vijesti':
                    //         catClass = 'news';
                    //     break;
                    // }
                    // news.catClass = catClass;
                    // var pubDate = moment(news.published).format("DD.MM.YYYY.");;
                    // news.pubDate = pubDate;
                    
                    if (category.gallery_image.length > 0) {
                        category.backgroundImage = category.gallery_image;
                    } else {
                        category.backgroundImage = '/images/default_background_image.png';
                    }

                    $scope.categories.push(category);
                    // if (category.parent == 0) {
                    // }
                }
            })

            .error(function(res, status){
                console.log('error status: ' + status);
                console.debug(res);
            });
        }
            
        $scope.getFeed('stores.json');
        
	}]);
});