define(["jquery","global/all","./Users.Forms","modules/ExpressShipTo/ExpressShipToCheckout"],function(e,t,o,n){"use strict";function r(){t.Core.handleEnter("#login_email, #login_password",L)}function i(){t.Core.handleEnter("#login_email_header, #login_password_header",M)}function a(){e(".marketing-portal__body").length>0&&e(".toggle-password-visibility").click(function(t){"text"==e(this).closest("div").find("input").attr("type")?(e(this).closest("div").find("input").attr("type","password"),e(this).text("Show Password")):(e(this).closest("div").find("input").attr("type","text"),e(this).text("Hide Password"))})}function s(){t.Core.handleEnter("#register_first_name, #register_last_name, #register_email, #register_email2, #register_password, #register_password2, #register_address1, #register_address2, #register_city, #register_state, #register_region, #register_country, #register_county, #register_zip, #register_phone",b)}function c(){t.Core.handleEnter("#forgot_email",J)}function l(){t.Core.handleEnter("#forgot_password, #forgot_password2",H)}function d(){t.Core.handleEnter("#current-password, #new-password, #new-password-confirm",$)}function u(){e(document).on("click",ne.login,function(){L()})}function g(){e(document).on("click",ne.loginHeader,function(){(e(".formee-msg-error").length||e(".contentBox-error").length)&&setTimeout(function(){e(document).find(".rocMenu").addClass("in").css("height","auto")},500),M()})}function f(){e(document).on("click",ne.register,function(){b()})}function m(){var t=e(ie),o=e(ae);e(re).is(":checked")?(t.show(),o.show()):(t.hide(),o.hide())}function p(){m(),e(document).on("change",re,function(){m()})}function h(){e(document).on("click",ne.forgotPass,function(){J()})}function E(){e(document).on("click",ne.changePass,function(){H()})}function y(){e(document).on("blur","#login_email",function(){var t=e("#btnForgotPassword"),o=t.attr("href");o&&(o.indexOf("?")>-1&&(o=o.substr(0,o.indexOf("?"))),o+="?Email="+encodeURIComponent(e(z.email.Field).val()),t.attr("href",o))})}function v(){e(document).on("blur","#login_email_header",function(){var t=e("#btnForgotPasswordHeader"),o=t.attr("href");o&&(o.indexOf("?")>-1&&(o=o.substr(0,o.indexOf("?"))),o+="?Email="+encodeURIComponent(e(Y.email.Field).val()),t.attr("href",o))})}function w(){e(document).on("click",ne.editAccount,function(){$()})}function P(){e(document).on("click",ne.editProfile,function(){W()})}function S(){e(document).on("click",ne.editAccountCancel,function(){t.Core.lockButton(ne.editAccountCancel),window.location.href=ee})}function F(){e(document).on("click",ne.editProfileCancel,function(){t.Core.lockButton(ne.editProfileCancel),window.location.href=document.URL})}function C(e){window.RocConfig.google.enableAddressAutocomplete===!0&&(e=e||"US",t.UI.addresscomplete("#register_address1",{country:e,autopopulate:!0,fieldsMapping:{STREET_ADDRESS_AND_NUMBER:"#register_address1",COUNTRY:"#register_country",ZIP:"#register_zip",CITY:"#register_city",STATE_OR_REGION:"US"===e||"CA"===e?"#register_state":"#register_region",COUNTY:"#register_county"},validation:{componentsToValidate:["street_number"],onValidationFailed:function(e){t.UI.warning("Address could not be validated, please confirm address is correct")}}}))}function T(){r(),y(),u()}function _(){i(),v(),g()}function O(){s(),f(),p(),t.EventManager.bind(t.Events.users.REGISTER,function(e){var o=e.responseJSON||{};o.success&&o.redir&&(t.Core.lockButton(ne.register),window.location.replace(o.redir))})}function k(){c(),l(),h(),E()}function U(){d(),w(),S()}function j(){P(),F()}function A(e){D=e||{},z={email:t.Validation.getField(oe.Login,"Email")},T()}function N(){Y={email:t.Validation.getField(oe.LoginHeader,"Email")},_()}function I(e){q=e||{},O(),C()}function x(o){Z=o||{},K={$pass:e(t.Validation.getField(oe.ChangePassword,"Password").Field),$pass2:e(t.Validation.getField(oe.ChangePassword,"Confirm Password").Field)},k()}function V(o){o&&(this.editAccountOptions=o,ee=o.myAccountUrl),Q={$newPass1:e(t.Validation.getField(oe.EditAccount,"New Password").Field),$newPass2:e(t.Validation.getField(oe.EditAccount,"Retype New Password").Field)},U()}function B(o){o&&(this.editAccountOptions=o,ee=o.myAccountUrl),X={$firstName:e(t.Validation.getField(oe.EditProfile,"First Name").Field),$lastName:e(t.Validation.getField(oe.EditProfile,"Last Name").Field)},j()}function L(){var o=e(oe.Login.Fields[0].Field).closest(".formee"),n=t.UI.getErrorSummaryWrapper(o),r=t.Validation.validateForm(oe.Login);if(D=D||{},r){t.Core.lockButton(ne.login);var i=t.Validation.getFieldValues(oe.Login);return i.isCheckout=D.isCheckout||!1,e.ajax({url:"/ajax/Login",type:"POST",contentType:"application/json",dataType:"json",data:JSON.stringify(i),beforeSend:D.beforeSend||null,complete:function(e){var o=e.responseJSON||{};o.errorMessage&&t.UI.template("formErrorSummary-Tmp",{message:o.errorMessage}).then(function(e){n.html(e)}),t.Core.releaseLockedButton(ne.login),t.EventManager.notify(t.Events.users.LOGIN,e)}})}}function M(){var o=e(oe.LoginHeader.Fields[0].Field).closest(".formee"),n=t.UI.getErrorSummaryWrapper(o),r=t.Validation.validateForm(oe.LoginHeader);if(r){t.Core.lockButton(ne.loginHeader);var i=t.Validation.getFieldValues(oe.LoginHeader);return i.isCheckout=!1,e.ajax({url:"/ajax/Login",type:"POST",contentType:"application/json",dataType:"json",data:JSON.stringify(i),complete:function(e){var o=e.responseJSON||{};t.Core.releaseLockedButton(ne.loginHeader),o.errorMessage?t.UI.template("formErrorInlineMsg-Tmp",{errorText:o.errorMessage}).then(function(e){n.html(e)}):o.redir?window.location.href=o.redir:t.EventManager.notify(t.Events.users.LOGIN,e)}})}}function R(o){return e.ajax({url:o||"/ajax/Logout",type:"POST",contentType:"application/json",dataType:"json",complete:function(e){t.EventManager.notify(t.Events.users.LOGOUT,e)}}),!1}function b(){var o=e(oe.Registration.Fields[0].Field).closest(".formee"),n=t.UI.getErrorSummaryWrapper(o);n.html("");var r=t.Validation.validateForm(oe.Registration);if(r){t.Core.lockButton(ne.register);var i=t.Forms.getFormValues(oe.Registration);i.authenticateUser=q.authenticateUser,i.duringCheckout=q.duringCheckout,e.ajax({url:"/ajax/Register",type:"POST",contentType:"application/json",dataType:"json",data:JSON.stringify(i),beforeSend:q.beforeSend||null,complete:function(e){var o=e.responseJSON||{};o.errorMessage&&t.UI.template("formErrorSummary-Tmp",{message:o.errorMessage}).then(function(e){n.html(e)}),t.Core.releaseLockedButton(ne.register),t.EventManager.notify(t.Events.users.REGISTER,e)}})}return r}function J(){var o=e(oe.ForgotPassword.Fields[0].Field).closest(".formee"),n=t.UI.getErrorSummaryWrapper(o),r=t.Validation.validateForm(oe.ForgotPassword);if(n.html(""),r){t.Core.lockButton(ne.forgotPass);var i=t.Validation.getFieldValues(oe.ForgotPassword);e.ajax({url:"/ajax/SendForgotPasswordEmail",type:"POST",data:JSON.stringify(i),contentType:"application/json",dataType:"json",complete:function(o){var r=o.responseJSON||{};r.success&&(e("#forgotForm").hide(),e("#checkEmail").show()),r.errorMessage&&t.UI.template("formErrorSummary-Tmp",{message:r.errorMessage}).then(function(e){n.html(e)}),t.Core.releaseLockedButton(ne.forgotPass),t.EventManager.notify(t.Events.users.FORGOT_PASSWORD,o)}})}}function H(){var o=e(oe.ChangePassword.Fields[0].Field).closest(".formee"),n=t.UI.getErrorSummaryWrapper(o),r=t.Validation.validateForm(oe.ChangePassword);if(n.html(""),r)if(K.$pass.val()!==K.$pass2.val())t.UI.template("formErrorSummary-Tmp",{message:"Given passwords aren't the same"}).then(function(e){n.html(e)});else{t.Core.lockButton(ne.changePass);var i=t.Validation.getFieldValues(oe.ChangePassword);e.ajax({url:"/ajax/ResetPassword",type:"POST",data:JSON.stringify(i),contentType:"application/json",dataType:"json",complete:function(e){var o=e.responseJSON||{};o.success&&o.redir?window.location.replace(o.redir):o.errorMessage?t.UI.template("formErrorSummary-Tmp",{message:o.errorMessage}).then(function(e){n.html(e)}):t.UI.ajaxErrorPopup(e),t.Core.releaseLockedButton(ne.changePass),t.EventManager.notify(t.Events.users.CHANGE_PASSWORD,e)}})}}function W(){var o=e(oe.EditProfile.Fields[0].Field).closest(".formee"),n=t.UI.getErrorSummaryWrapper(o),r=t.Validation.validateForm(oe.EditProfile);if(r){var i=t.Validation.getFieldValues(oe.EditProfile);e.ajax({url:"/ajax/EditUserProfile",type:"POST",data:JSON.stringify(i),contentType:"application/json",dataType:"json",complete:function(e){var o=e.responseJSON||{};o.errorMessage&&t.UI.template("formErrorSummary-Tmp",{message:o.errorMessage}).then(function(e){n.html(e)}),t.Core.releaseLockedButton(ne.editProfile),t.EventManager.notify(t.Events.users.EDIT_ACCOUNT,e)}})}}function $(){var o=e(oe.EditAccount.Fields[0].Field).closest(".formee"),n=t.UI.getErrorSummaryWrapper(o),r=t.Validation.validateForm(oe.EditAccount);if(n.html(""),r)if(Q.$newPass1.val()!==Q.$newPass2.val())t.UI.template("formErrorSummary-Tmp",{message:'"New Password" and "Confirm New Password" aren\'t the same'}).then(function(e){n.html(e)});else{t.Core.lockButton(ne.editAccount);var i=t.Validation.getFieldValues(oe.EditAccount);e.ajax({url:"/ajax/EditAccount",type:"POST",data:JSON.stringify(i),contentType:"application/json",dataType:"json",complete:function(e){var o=e.responseJSON||{};o.errorMessage&&t.UI.template("formErrorSummary-Tmp",{message:o.errorMessage}).then(function(e){n.html(e)}),t.Core.releaseLockedButton(ne.editAccount),t.EventManager.notify(t.Events.users.EDIT_ACCOUNT,e)}})}}function G(){return null!==t.Core.getCookie("access_token")}var D,z,Y,q,Z,K,Q,X,ee,te={},oe=o;n.addExpressShipToToForm(oe.Registration.Fields,!0),a();var ne={login:"#loginBtn",loginHeader:"#loginBtnHeader",register:"#registerBtn",forgotPass:"#forgotPasswordBtn",changePass:"#changePasswordBtn",editAccount:"#editAccountSaveBtn",editAccountCancel:"#editAccountCancelBtn",editProfile:"#editProfileSaveBtn",editProfileCancel:"#editProfileCancelBtn"},re="#requestBusinessAccount",ie="#orgaizationNameWrapper",ae="#expressShipToWrapper",se={forms:oe,initLogin:A,initLoginHeader:N,initRegistration:I,initForgotPassword:x,initEditAccount:V,initEditProfile:B,login:L,logout:R,register:b,forgotPassword:J,changePassword:H,editAccount:$,editAccountOptions:te,isLoggedIn:G};return t.Logger.debug("Users.js Loaded:",se),se});
//# sourceMappingURL=Users.js.map