define(["angular","cjt/util/locale","cjt/validator/validator-utils","cjt/validator/validateDirectiveFactory","app/services/userService"],(function(e,t,n,a,r){"use strict";var i=e.module("App");i.directive("usernameWithDomainWrapper",[function(){var t=function(e){this.username=this.domain="",this.$attrs=e};return e.extend(t.prototype,{setDomain:function(e){return void 0!==e&&(this.domain=e),this.getTotalLength()},setUsername:function(e){return void 0!==e&&(this.username=e),this.getTotalLength()},getUsernameAndDomain:function(){return this.username+"@"+this.domain},getTotalLength:function(){return this.getUsernameAndDomain().length}}),{restrict:"A",scope:!1,controller:["$attrs",t]}}]),i.directive("usernameWithDomain",["userService","$q",function(e,r){return{restrict:"A",scope:!1,require:["^^usernameWithDomainWrapper","ngModel"],link:function(i,o,s,u){var l=u[0],c=u[1],m=s.usernameWithDomain;if("username"===m){l.validateUsername=c.$validate;var d=o.controller("form");n.initializeExtendedReporting(c,d);var h=function(e){var a=n.initializeValidationResult();return e>254&&a.addError("maxLength",t.maketext("The combined length of the username, [asis,@] character, and domain cannot exceed [numf,_1] characters.",254)),a};c.$validators.usernameWithDomain=function(e){var t=l.setUsername(e);return a.run("usernameWithDomain",c,d,h,t)};var v=function(t){return e.checkAccountConflicts(t).then((function(e){return i.$eval(l.$attrs.lookupCallback,{responseData:e}),e})).then((function(){return n.initializeValidationResult()}),(function(e){var t=n.initializeValidationResult(!0);return t.addError("usernameIsAvailable",e),t}))};c.$asyncValidators.usernameIsAvailable=function(e,t){var n=l.getUsernameAndDomain();return a.runAsync(r,"usernameIsAvailable",c,d,v,n)}}else{if("domain"!==m)throw new Error("The value for the username-with-domain directive needs to be set to 'username' or 'domain'.");c.$formatters.push((function(e){return l.setDomain(c.$modelValue),e})),c.$viewChangeListeners.push((function(){l.setDomain(c.$modelValue),l.validateUsername()}))}}}}])}));