angular.module('avalanche3mobile.controllers', [])

.controller('AppCtrl', function($scope, $rootScope, $location, $ionicModal, $timeout, missionData, $ionicSideMenuDelegate, $cordovaStatusbar, $state) {



  // With the new view caching in Ionic, Controllers are only called
  // when they are recreated or on app start, instead of every page change.
  // To listen for when this page is active (for example, to refresh data),
  // listen for the $ionicView.enter event:
  //$scope.$on('$ionicView.enter', function(e) {
  //});

  // Form data for the login modal
  $scope.loginData = {};

  $scope.currentMissions = missionData.get();

  $scope.mission = missionData.getCurrentMission();

  $rootScope.$on('$stateChangeSuccess',
    function(event, toState, toParams, fromState, fromParams){
      $scope.mission = missionData.getCurrentMission();
  });

  $scope.isActive = function (viewLocation) {
    //console.log(viewLocation + " | " + $location.path())
    console.log($state.params.missionId)
    if($state.params.missionId == viewLocation) { return true; }
    else { return false; }
  };

  // Create the login modal that we will use later
  $ionicModal.fromTemplateUrl('templates/login.html', {
    scope: $scope
  }).then(function(modal) {
    $scope.modal = modal;
  });

  // Triggered in the login modal to close it
  $scope.closeLogin = function() {
    $scope.modal.hide();
  };

  // Open the login modal
  $scope.login = function() {
    $scope.modal.show();
  };

  // Perform the login action when the user submits the login form
  $scope.doLogin = function() {
    console.log('Doing login', $scope.loginData);

    // Simulate a login delay. Remove this and replace with your login
    // code if using a login system
    $timeout(function() {
      $scope.closeLogin();
    }, 1000);
  };

  $scope.toggleLeft = function() {
    console.log("Opening left menu")
    $ionicSideMenuDelegate.toggleLeft();
    // if($cordovaStatusbar.isVisible()){
    //   //$cordovaStatusbar.hide();
    // } else {
    //   //$cordovaStatusbar.show();
    // }

  };

})

.controller('PlaylistsCtrl', function($scope) {
  $scope.playlists = [
    { title: 'Reggae', id: 1 },
    { title: 'Chill', id: 2 },
    { title: 'Dubstep', id: 3 },
    { title: 'Indie', id: 4 },
    { title: 'Rap', id: 5 },
    { title: 'Cowbell', id: 6 }
  ];
})

.controller('MissionTasksCtrl', function($scope, $stateParams, mission) {
  $scope.mission = mission;
  console.log(mission)
})

.controller('MissionAgentsCtrl', function($scope, $stateParams, mission) {
  $scope.mission = mission;
  console.log(mission)
});
