(function (app) {
    app.config(["$stateProvider", "$urlRouterProvider", function ($stateProvider, $urlRouterProvider) {
        $stateProvider
          .state('login', {
              url: '/account/login',
              templateUrl: 'templates/account/login.html',
              controller: 'loginCtrl'
          })
          .state('app', {
              url: '/app',
              abstract: true,
              templateUrl: "templates/tabs.html",
              controller: 'tabsCtrl'
          })
            .state('app.home', {
                url: '/home',
                views: {
                    'app-home': {
                        templateUrl: 'templates/home/index.html',
                        controller: 'homeCtrl'
                    }
                }
            })
            .state('app.my_dreamdetail', {
                url: '/my/dreamdetail',
                params:{id:null},
                views: {
                    'app-my': {
                        templateUrl: 'templates/home/dream-detail.html',
                        controller: 'dreamDetailCtrl'
                    }
                }
            })
            .state('app.home_dreamdetail', {
                url: '/home/dreamdetail',
                params:{id:null},
                views: {
                    'app-home': {
                        templateUrl: 'templates/home/dream-detail.html',
                        controller: 'dreamDetailCtrl'
                    }
                }
            })
            .state('app.home_search', {
                url: '/home/search',
                views: {
                    'app-home': {
                        templateUrl: 'templates/home/search.html',
                        controller: 'searchCtrl'
                    }
                }
            })
        .state('app.home_dream', {
            url: '/home/dream',
            views: {
                'app-home': {
                    templateUrl: 'templates/my/my-dream.html',
                    controller: 'homeDreamsCtrl'
                }
            }
        })
           .state('app.home_add', {
               url: '/home/add',
               views: {
                   'app-home': {
                       templateUrl: 'templates/add/index.html',
                       controller: 'addCtrl'
                   }
               }
           })
           .state('app.add', {
               url: '/add',
               views: {
                   'app-add': {
                       templateUrl: 'templates/add/index.html',
                       controller: 'addCtrl'
                   }
               }
           })
        .state('app.my', {
            url: '/my',
            views: {
                'app-my': {
                    templateUrl: 'templates/my/index.html',
                    controller: 'myCtrl'
                }
            }
        })
           .state('app.my_add', {
               url: '/my/add',
               views: {
                   'app-my': {
                       templateUrl: 'templates/add/index.html',
                       controller: 'addCtrl'
                   }
               }
           })
          .state('app.my_profile', {
              url: '/my/profile',
              views: {
                  'app-my': {
                      templateUrl: 'templates/my/my-profile.html',
                      controller: 'profileCtrl'
                  }
              }
          })
        .state('app.my_collect', {
            url: '/my/collect',
            views: {
                'app-my': {
                    templateUrl: 'templates/my/my-collect.html',
                    controller: 'collectCtrl'
                }
            }
        })
        .state('app.my_dream', {
            url: '/my/dream',
            views: {
                'app-my': {
                    templateUrl: 'templates/my/my-dream.html',
                    controller: 'dreamCtrl'
                }
            }
        })
        .state('app.my_message', {
            url: '/my/message',
            views: {
                'app-my': {
                    templateUrl: 'templates/my/my-message.html',
                    controller: 'messageCtrl'
                }
            }
        })
        .state('app.my_message_sys', {
                url: '/my/message/sys',
                views: {
                    'app-my': {
                        templateUrl: 'templates/my/my-message-sys.html',
                        controller: 'messageSysCtrl'
                    }
                }
        })
        .state('app.my_message_reply', {
            url: '/my/message/reply',
            views: {
                'app-my': {
                    templateUrl: 'templates/my/my-message-reply.html',
                    controller: 'messageReplyCtrl'
                }
            }
        })
        .state('app.my_recharge', {
            url: '/my/recharge',
            views: {
                'app-my': {
                    templateUrl: 'templates/my/my-recharge.html',
                    controller: 'rechargeCtrl'
                }
            }
        })
        .state('app.my_setting', {
            url: '/my/setting',
            views: {
                'app-my': {
                    templateUrl: 'templates/my/my-setting.html',
                    controller: 'settingCtrl'
                }
            }
        })
        if (localStorage['token']) {
            $urlRouterProvider.otherwise('/app/home');
        } else {
            $urlRouterProvider.otherwise('/account/login');
        }

    }]);
})(angular.module('app'));