(function (angular, undefined) {
    'use strict';
    
    angular.module('general.directives', [])
        
        .directive('coDate', function ($window) {
		    return {
		        restrict: 'A',
		        require: 'ngModel',
		        scope:{

		        },
		        link: function (scope, element, attrs, ngModel) {
		            
		            var vm = this;

		            vm.expectedFormat = 'YYYY-MM-DD HH:mm:ss';
		            vm.outputFormat   = 'DD/MM/YYYY';
	                
	                // console.log('scope', scope);
	                // console.log('element', element);
	                // console.log('attrs', attrs);
	                // console.log('ngModel', ngModel);

	                // ngModel.$viewValue = _format(ngModel.$modelValue);

		            element.on('change', function (e) {
		                e.target.value = _format(ngModel.$modelValue);
		            });

		            function _format(data)
		            {
		            	return moment(ngModel.$modelValue, vm.expectedFormat).format(vm.outputFormat);
		            }

		        } //link
    		};
    	});

})(angular);