// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js

window.ionic.Platform.ready(function() {
    angular.bootstrap(document, ['avalanche3mobile']);
});

angular.module('avalanche3mobile', [
  'ionic',
  'ngCordova',
  'ionic.utils',
  'avalanche3mobile.controllers',
  'avalanche3mobile.missionData',
  'avalanche3mobile.LoginCtrl',
  'avalanche3mobile.MissionCtrl',
  'avalanche3mobile.BriefingCtrl',
  'avalanche3mobile.ActivityCtrl',
  'avalancheServices.Oauth',
  'avalancheServices.Data',
  'avalancheServices.Realtime'
])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }

  });
})

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

  .state('app', {
    url: "/app",
    abstract: true,
    templateUrl: "templates/menu.html",
    controller: 'AppCtrl'
  })

  .state('mission', {
    url: "/missions",
    abstract: true,
    templateUrl: "templates/menu.html",
    controller: 'MissionCtrl'
  })

  .state('simple', {
    url: "/simple",
    abstract: true,
    templateUrl: "templates/simple.html",
    controller: 'AppCtrl'
  })

  .state('simple.login', {
    url: "/login",
    views: {
      'menuContent': {
        templateUrl: "templates/login.html",
        controller: 'LoginCtrl'
      }
    }

  })

  .state('app.search', {
    url: "/search",
    views: {
      'menuContent': {
        templateUrl: "templates/search.html",
        controller: 'MissionBriefingCtrl'
      }
    }
  })

  .state('app.browse', {
    url: "/browse",
    views: {
      'menuContent': {
        templateUrl: "templates/browse.html"
      }
    }
  })
  .state('app.playlists', {
    url: "/playlists",
    views: {
      'menuContent': {
        templateUrl: "templates/playlists.html",
        controller: 'PlaylistsCtrl'
      }
    }
  })

  .state('mission.briefing', {
    url: "/missions/:missionId/briefing",
    views: {
      'menuContent': {
        templateUrl: "templates/mission_briefing.html",
        controller: 'MissionBriefingCtrl'
      }
    },
    resolve:{
      mission:  function(missionData, $stateParams){
        return missionData.findMission($stateParams.missionId)
      }
    }
  })
  .state('mission.activity', {
    url: "/missions/:missionId/activity",
    views: {
      'menuContent': {
        templateUrl: "templates/mission_activity.html",
        controller: 'MissionActivityCtrl'
      }
    },
    resolve:{
      mission:  function(missionData, $stateParams){
        return missionData.findMission($stateParams.missionId)
      }
    }
  })

  .state('mission.tasks', {
    url: "/missions/:missionId/tasks",
    views: {
      'menuContent': {
        templateUrl: "templates/mission_tasks.html",
        controller: 'MissionTasksCtrl'
      }
    },
    resolve:{
      mission:  function(missionData, $stateParams){
        return missionData.findMission($stateParams.missionId)
      }
    }
  })

  .state('mission.agents', {
    url: "/missions/:missionId/agents",
    views: {
      'menuContent': {
        templateUrl: "templates/mission_agents.html",
        controller: 'MissionAgentsCtrl'
      }
    },
    resolve:{
      mission:  function(missionData, $stateParams){
        return missionData.findMission($stateParams.missionId)
      }
    }
  })
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/simple/login');
});
