/**
 * @author monitour
 * created on 27.07.2017
 */
(function() {
	'use strict';
	angular.module('Monitour.pages.billing').controller('purchaseCtrl', purchaseCtrl);
	/** @ngInject */
	function purchaseCtrl($scope,  $http, $localStorage ,$state,  SweetAlert,  $translate, $stateParams, $filter, UserService) {
		var vm = this;
		
        vm.owner = $localStorage.currentUser;
		var id = $stateParams.id;
		vm.purchase = purchase;
		$scope.today = new Date();

		$scope.addMonths = function(months) {
			var result = new Date($scope.today);
			result.setMonth(result.getMonth() + months);
			return result;
		};
	
		$scope.card = {};
		console.log($scope.card);
		  $scope.isVisa = function(){
			if($scope.card.number && $scope.card.number.charAt(0) == 4){
			  return true;
			}else{
			  return false;
			}
		  };
		
		  $scope.isMasterCard = function(){
			if($scope.card.number && $scope.card.number.charAt(0) == 5){
			  return true;
			}else{
			  return false;
			}
		  };

		if (id == 1) {
           vm.heading = $filter('translate')('purchase.titlebronze');
		   vm.monthlycost = '29.99';
			vm.price = '29.99';
			vm.plan = 'Per Month';
			vm.month = $scope.addMonths(1);
        } 
		if (id == 2) {
           vm.heading = $filter('translate')('purchase.titlesilver');
		   vm.monthlycost = '28.50';
			vm.price = '85.50';
			vm.plan ='3 Month plan';
			vm.saving = '$4.47 of savings';
			vm.month = $scope.addMonths(3);
        } 
		if (id == 3) {
           vm.heading = $filter('translate')('purchase.titlegold');
		   vm.monthlycost = '27.00';
			vm.price = '162.00';
			vm.plan = '6 Month Plan';
			vm.saving = '$17.94 of savings';
			vm.month = $scope.addMonths(6);
        } 
		if (id == 4) {
           vm.heading = $filter('translate')('purchase.titleplatinum');
		   vm.monthlycost = '25.50';
			vm.price = '229.50';
			vm.plan = '9 Month Plan';
			vm.saving = '$40.41 of savings';
			vm.month = $scope.addMonths(9);
        } 
		if (id == 5) {
           vm.heading = $filter('translate')('purchase.titlediamond');
		   vm.monthlycost = '24.00';
		   vm.price = '288.00';
		   vm.plan = '12 Month Plan';
		   vm.saving = '$71.88 of savings';
		   vm.month = $scope.addMonths(12);
        } 
        var id = $localStorage.currentUserid;
		
       
		UserService.GetById(id).then(function (response) {
			vm.firstname = response.data[0].firstname;
			vm.lastname = response.data[0].lastname;
			   console.log(response);
        }, function (error) {
           console.log(error);
        });

     vm.today = new Date();
		
		var nextMonth = new Date(vm.today);

          vm.date =  nextMonth.setMonth(vm.today.getMonth()+1);
		

		  function purchase() {
    alert('plan' +  vm.heading + "\n" + 'user' + id + "\n" + 'first name' + vm.firstname + "\n" + 'Card number: ' + $scope.card.number + "\n" + 'Card holder: ' + $scope.card.holder + "\n" + 'Expiry date: ' + $scope.card.date + "\n" + 'Card CVV: ' + $scope.card.cvv );
  };
		console.log(id);
      
	}
})();