/**
 * SmsCtrl Controller
 * Extracted from bookings module
 */

Bookings.controller('SmsCtrl', ['$scope', '$uibModalInstance', 'task', '$http', 'ErrorsHandler', 'mobile', 'apiUrl', 'Messenger', 'CustomerNotificationsService', 'Tasks', function ($scope, $uibModalInstance, task, $http, ErrorsHandler, mobile, apiUrl, Messenger, CustomerNotificationsService, Tasks) {

	var task_id = task ? task.id : '';

	$scope.data = {
		send_to: mobile,
		message: 'Your repair ' + task_id + ' is now ready to be collected. Computer Assistance',
		task_id: task_id
	};

	$scope.submit = function () {
		if ($scope.sending) return false;

		$scope.sending = true;

		var params = {
			send_to: $scope.data.send_to,
			message: $scope.data.message,
			id: $scope.data.task_id
		};

		Tasks.sendSMS(params, function (response) {
			$scope.sending = false;
			CustomerNotificationsService.notifications.push(response.notification);
			Messenger("Your SMS has been successfully sent to the client and should be delivered shortly");
			$uibModalInstance.close();
		}, function (a, b) {
			$scope.sending = false;
			ErrorsHandler(a, b);
		});

	};

	$scope.cancel = function () {
		$uibModalInstance.dismiss('cancel');
	};

}]);
