app.controller('SelectMenuPageController',['$scope','$firebaseObject','$timeout',function($scope,$firebaseObject,$timeout){
  var ref = firebase.database().ref().child('meals');
  // var fireObj = $firebaseObject(ref);keys[i]
  // var mealItems = fireObj.first;
  // fireObj.$loaded().then(function(result){
  //   console.log(result.first);
  // })
  $scope.mealType = 'breakfast';
  $scope.meals = [];
  $scope.selectedNumber = 0;
  $scope.selectMeal = function(i){
    var keys = Object.keys($scope.meals);

    //animating btn
    if(!$scope.meals[keys[i]].isSelected){
      var selectedMealsBtn = angular.element(document.querySelector('.selected-meals-btn'));
      selectedMealsBtn.addClass('selected-meals-btn-animate');
      $timeout(function(){
        selectedMealsBtn.removeClass('selected-meals-btn-animate');
      },500)
    }
    //animating btn

    $scope.meals[keys[i]].isSelected = true;
    ref.child(keys[i]).set($scope.meals[keys[i]]);
  }
  ref.on('value', snap => {
    // var databaseT0ests = [];
    // var retrievedObject = snap.val();
    // if(retrievedObject){
    //   var keys = Object.keys(retrievedObject);
    //   for (var i = 0; i < keys.length; i++) {
    //     databaseTests[i] = retrievedObject[keys[i]];
    //   }
    // }
    $timeout(function(){
      $scope.meals = snap.val();
    })
  })

}])
