// Generated by CoffeeScript 1.10.0
var AppController, MainController, ModalNewDeckController, NavController;

AppController = (function() {
  function 
($scope) {
    this.scope = $scope;
    this.scope.$on('search', function(term) {
      return console.log(term);
    });
    $scope.$on('deckHasBeenSelected', function(deck) {
      $scope.currentDeck = deck.targetScope.currentDeck;
      return $scope.$broadcast('currentDeckHasChanged');
    });
  }

  return AppController;

})();

NavController = (function() {
  function NavController($scope, $uibModal, $localStorage) {
    if (!$localStorage.decks) {
      $localStorage.decks = [];
    }
    $scope.decks = $localStorage.decks;
    $scope.selectDeck = function(deck) {
      $scope.currentDeck = deck;
      return $scope.$emit('deckHasBeenSelected', $scope.currentDeck);
    };
    $scope.selectDeck($scope.decks[0]);
    $scope.addDeck = function($scope) {
      var modal;
      modal = $uibModal.open({
        templateUrl: "template/modalNewDeck.html",
        controller: "modalNewDeckController"
      });
      return modal.result.then(function(deckName) {
        return $localStorage.decks.push(new Deck(deckName));
      });
    };
  }

  return NavController;

})();

ModalNewDeckController = (function() {
  function ModalNewDeckController($scope, $uibModalInstance) {
    $scope.cancel = function() {
      return $uibModalInstance.dismiss("cancel");
    };
    $scope.submit = function() {
      return $uibModalInstance.close($scope.name);
    };
  }

  return ModalNewDeckController;

})();

MainController = (function() {
  function MainController($scope, $localStorage, $http) {
    $scope.cards = [];
    $scope.$on("currentDeckHasChanged", function(e) {
      $scope.currentDeck = e.targetScope.currentDeck;
      return $scope.load();
    });
    $scope.load = function() {
      return $scope.cards = $scope.currentDeck.cards;
    };
    $scope.addNewCard = function() {
      $scope.cards.push(new Card($scope.title, $scope.description));
      $scope.title = "";
      return $scope.description = "";
    };
  }

  return MainController;

})();

myApp.controller('appController', AppController);

myApp.controller('navController', NavController);

myApp.controller('mainController', MainController);

myApp.controller('modalNewDeckController', ModalNewDeckController);

AppController