(function() {
	'use strict';

	window.app.directive('monthQuery',
		function() {
			return {
				scope: {
					queryFn: '='
				},
				templateUrl: '/utility/template/monthQuery.tmpl.cshtml',
				controller: controller,
				controllerAs: 'vm'
			}
		});

	controller.$inject = ['$scope'];
	function controller($scope) {
		var vm = this;
		vm.query = {};
		vm.submitting = false;
		vm.errorMessages = [];
		vm.submit =
			function() {
				vm.submitting = true;
				$scope.queryFn({ month: vm.query })
					.error(function(data) {
						vm.errorMessages
							= angular.copy(data.errorMessages, vm.errorMessages);
					})
					.finally(function() {
						vm.submitting = false;
					});
			};
	}
})();