text: 'use strict';
  
  angular.module('admin.content', ['ngTable', 'ui.tree'])
      .config([
          '$stateProvider',
          function($stateProvider) {
              var viewPath = 'gzero/admin/views/content/';
              // Now set up the states
              $stateProvider
                  .state('content', {
                      url: '/content',
                      controller: 'ContentDashboardCtrl',
                      templateUrl: viewPath + 'index.html',
                      resolve: {
                          categories: [
                              'ContentRepository', function(ContentRepository) {
                                  // get tree of all categories
                                  return ContentRepository.tree({
                                      only_categories: true
                                  });
                              }
                          ]
                      }
                  })
                  // CONTENT LIST
                  .state('content.list', {
                      url: '/list/{contentId}?is_active&page&perPage',
                      resolve: {
                          listParent: [
                              '$stateParams', 'Utils', 'ContentRepository', function($stateParams, Utils, ContentRepository) {
                                  // if state param has category id
                                  if ($stateParams.contentId) {
                                      Utils.Storage.setStorageItem({contentListParent: $stateParams.contentId});
                                      return ContentRepository.one($stateParams.contentId);
                                  } else {
                                      // if storage has category id
                                      if (Utils.Storage.getStorageItem('contentListParent')) {
                                          $stateParams.contentId = Utils.Storage.getStorageItem('contentListParent');
                                          return ContentRepository.one(Utils.Storage.getStorageItem('contentListParent'));
                                      }
                                  }
                              }
                          ],
                          openCategories: [
                              // get open categories from Storage
                              'Utils', function(Utils) {
                                  return Utils.Storage.getStorageItem('openCategories');
                              }
                          ]
                      },
                      views: {
                          'content': {
                              templateUrl: viewPath + 'list.html',
                              controller: 'ContentListCtrl'
                          },
                          'quickSidebarLeft': {
                              templateUrl: viewPath + 'categories.html',
                              controller: 'ContentCategoryTreeCtrl'
                          }
                      }
                  })
                  // CONTENT SHOW
                  .state('content.show', {
                      url: '/{contentId}/show/{langCode}',
                      abstract: [
                          // redirect to active tab on language change
                          '$state', function($state) {
                              return _.startsWith($state.current.name, 'content.show') ? $state.current.name : '.details';
                          }
                      ],
                      resolve: {
                          langCode: [
                              '$state', '$stateParams', function($state, $stateParams) {
                                  return $stateParams.langCode;
                              }
                          ],
                          content: [
                              '$stateParams', 'ContentRepository', function($stateParams, ContentRepository) {
                                  return ContentRepository.one($stateParams.contentId);
                              }
                          ],
                          author: [
                              'content', 'UserRepository', function(content, UserRepository) {
                                  return UserRepository.one(content.author_id);
                              }
                          ]
                      },
                      views: {
                          'content': {
                              templateUrl: viewPath + 'show.html',
                              controller: 'ContentDetailsCtrl'
                          },
                          'langSwitcher@content.show': {
                              templateUrl: viewPath + 'details/langSwitcher.html'
  
                          },
                          'contentSettings@content.show': {
                              templateUrl: viewPath + 'details/settings.html'
  
                          }
                      }
                  })
                  .state('content.show.details', {
                      url: '/details',
                      deepStateRedirect: true,
                      sticky: true,
                      views: {
                          'contentTab': {
                              templateUrl: viewPath + 'details/tabs/details.html'
                          }
                      }
                  })
                  .state('content.show.history', {
                      url: '/history?isActive&type&page&perPage',
                      deepStateRedirect: true,
                      sticky: true,
                      views: {
                          'contentTab': {
                              templateUrl: viewPath + 'details/tabs/history.html',
                              controller: 'ContentHistoryCtrl'
                          }
                      }
                  })
                  .state('content.show.blocks', {
                      url: '/blocks',
                      deepStateRedirect: true,
                      sticky: true,
                      resolve: {
                          blocks: [
                              '$stateParams', 'ContentRepository', function($stateParams, ContentRepository) {
                                  return ContentRepository.blocks($stateParams.contentId, {language_code: $stateParams.langCode});
                              }
                          ]
                      },
                      views: {
                          'contentTab': {
                              templateUrl: viewPath + 'details/tabs/blocks.html',
                              controller: 'ContentBlocksCtrl'
                          }
                      }
                  })
                  .state('content.show.files', {
                      url: '/files/{type}',
                      deepStateRedirect: true,
                      sticky: true,
                      resolve:{
                          entity: function(content){
                              return content;
                          }
                      },
                      views: {
                          'contentTab': {
                              templateUrl: 'gzero/admin/views/core/details/tabs/files.html',
                              controller: 'EntityFilesCtrl'
                          }
                      }
                  })
                  // CONTENT EDIT
                  .state('content.edit', {
                      url: '/{contentId}/edit/{langCode}',
                      abstract: '.index',
                      resolve: {
                          langCode: [
                              '$state', '$stateParams', function($state, $stateParams) {
                                  return $stateParams.langCode;
                              }
                          ],
                          content: [
                              '$stateParams', 'ContentRepository', function($stateParams, ContentRepository) {
                                  return ContentRepository.one($stateParams.contentId);
                              }
                          ],
                          author: [
                              'content', 'UserRepository', function(content, UserRepository) {
                                  return UserRepository.one(content.author_id);
                              }
                          ]
                      },
                      data: {
                          showMask: true // enter edit mode
                      },
                      views: {
                          'content': {
                              templateUrl: viewPath + 'show.html',
                              controller: 'ContentDetailsCtrl'
                          },
                          'langSwitcher@content.edit': {
                              templateUrl: viewPath + 'details/langSwitcher.html'
  
                          },
                          'contentSettings@content.edit': {
                              templateUrl: viewPath + 'details/settings.html'
  
                          }
                      }
                  })
                  .state('content.edit.index', {
                      url: '',
                      views: {
                          'contentTab': {
                              templateUrl: viewPath + 'details/tabs/details.html'
                          }
                      }
                  })
                  .state('content.edit.details', {
                      url: '/details',
                      views: {
                          'contentTab': {
                              controller: 'ContentDetailsEditCtrl',
                              templateUrl: viewPath + 'details/tabs/detailsEdit.html'
                          }
                      }
                  })
                  // CONTENT TRASHCAN
                  .state('content.trashcan', {
                      url: '/trashcan?is_active&type&page&perPage',
                      resolve: {
                          listParent: [
                              function() {
                                  return undefined;
                              }
                          ],
                          openCategories: [
                              // get open categories from Storage
                              'Storage', function(Storage) {
                                  return Storage.getStorageItem('openCategories');
                              }
                          ]
                      },
                      views: {
                          'content': {
                              templateUrl: viewPath + 'trashcan.html',
                              controller: 'ContentTrashcanCtrl'
                          },
                          'quickSidebarLeft': {
                              templateUrl: viewPath + 'categories.html',
                              controller: 'ContentCategoryTreeCtrl'
                          }
                      }
                  })
                  // CONTENT ADD
                  .state('content.add', {
                      url: '/add/{type}',
                      resolve: {
                          listParent: [
                              'Utils', 'ContentRepository', function(Utils, ContentRepository) {
                                  // if storage has category id
                                  if (Utils.Storage.getStorageItem('contentListParent')) {
                                      return ContentRepository.one(Utils.Storage.getStorageItem('contentListParent'));
                                  }
                              }
                          ]
                      },
                      views: {
                          'content': {
                              templateUrl: viewPath + 'add.html',
                              controller: 'ContentAddCtrl'
                          }
                      }
                  })
                  // CONTENT ADD TRANSLATION
                  .state('content.addTranslation', {
                      url: '/{contentId}/add-translation/{langCode}',
                      resolve: {
                          content: [
                              '$stateParams', 'ContentRepository', function($stateParams, ContentRepository) {
                                  return ContentRepository.one($stateParams.contentId);
                              }
                          ]
                      },
                      views: {
                          'content': {
                              templateUrl: viewPath + 'addTranslation.html',
                              controller: 'ContentAddTranslationCtrl'
                          }
                      }
                  });
          }
      ])
      .controller('ContentAddCtrl', require('./controllers/ContentAddCtrl'))
      .controller('ContentDeleteCtrl', require('./controllers/directives/ContentDeleteCtrl'))
      .controller('ContentRestoreCtrl', require('./controllers/directives/ContentRestoreCtrl'))
      .controller('ContentCategoryTreeCtrl', require('./controllers/ContentCategoryTreeCtrl'))
      .controller('ContentDashboardCtrl', require('./controllers/ContentDashboardCtrl'))
      .controller('ContentDetailsCtrl', require('./controllers/ContentDetailsCtrl'))
      .controller('ContentDetailsEditCtrl', require('./controllers/ContentDetailsEditCtrl'))
      .controller('ContentHistoryCtrl', require('./controllers/ContentHistoryCtrl'))
      .controller('ContentBlocksCtrl', require('./controllers/ContentBlocksCtrl'))
      .controller('ContentListCtrl', require('./controllers/ContentListCtrl'))
      .controller('ContentTrashcanCtrl', require('./controllers/ContentTrashcanCtrl'))
      .controller('ContentAddTranslationCtrl', require('./controllers/ContentAddTranslationCtrl'))
      .controller('ContentRouteCtrl', require('./controllers/directives/ContentRouteCtrl'))
      .controller('SetTranslationAsActiveCtrl', require('./controllers/directives/SetTranslationAsActiveCtrl'))
      .controller('TranslationDeleteCtrl', require('./controllers/directives/TranslationDeleteCtrl'))
      .controller('ContentTogglePropertyCtrl', require('./controllers/directives/ContentTogglePropertyCtrl'))
      .controller('ContentWeightEditCtrl', require('./controllers/directives/ContentWeightEditCtrl'))
      .controller('ContentThemeEditCtrl', require('./controllers/directives/ContentThemeEditCtrl'))
      .controller('ContentThumbCtrl', require('./controllers/directives/ContentThumbCtrl'))
      .controller('ContentPublishedAtEditCtrl', require('./controllers/directives/ContentPublishedAtEditCtrl'))
      .factory('ContentRepository', require('./services/ContentRepository.js'))
      .directive('contentDeleteButton', require('./directives/ContentDeleteButton.js'))
      .directive('contentRestoreButton', require('./directives/ContentRestoreButton.js'))
      .directive('contentEditRouteButton', require('./directives/ContentEditRouteButton.js'))
      .directive('setTranslationAsActiveButton', require('./directives/SetTranslationAsActiveButton.js'))
      .directive('translationDeleteButton', require('./directives/TranslationDeleteButton.js'))
      .directive('contentTogglePropertyButton', require('./directives/ContentTogglePropertyButton.js'))
      .directive('contentPublishedAtEditButton', require('./directives/ContentPublishedAtEditButton.js'))
      .directive('contentActionsDropdown', ['$dropdown', require('./directives/ContentActionsDropdown.js')])
      .directive('contentWeightEditButton', ['$dropdown', require('./directives/ContentWeightEditButton.js')])
      .directive('contentThemeEditButton', ['$dropdown', require('./directives/ContentThemeEditButton.js')])
      .directive('contentThumbButton', ['$dropdown', require('./directives/ContentThumbButton.js')])
      .directive('charactersCounter', require('./directives/CharactersCounter.js'))
      .run([
          'NavBar',
          function(NavBar) {
              NavBar.add(
                  {
                      title: 'CONTENT',
                      action: 'content.list',
                      icon: 'fa fa-file-text-o'
                  }
              );
              //NavBar.addLastChild(
              //    'CONTENT',
              //    {
              //        title: 'ALL_CONTENTS',
              //        action: 'content.list',
              //        icon: 'fa fa-th'
              //    }
              //);
              //NavBar.addLastChild(
              //    'CONTENT',
              //    {
              //        title: 'ADD_CONTENT',
              //        action: 'content.add({ type: "content" })',
              //        icon: 'fa fa-file-text-o'
              //    }
              //);
              //NavBar.addLastChild(
              //    'CONTENT',
              //    {
              //        title: 'ADD_CATEGORY',
              //        action: 'content.add({ type: "category" })',
              //        icon: 'fa fa-file-text'
              //    }
              //);
          }
      ]);
  