!function(e){"function"==typeof define&&define.amd?define("auth",e):e()}(function(){"use strict";jQuery(function(n){n('.picture-field input[type="file"]').on("change",function(e){var i=n(".sign-in-form.register .picture-field .picture-preview");if(i.html(""),e.target.files[0]){var t=new FileReader;t.onload=function(e){var t=n('<div class="review-gallery-image">\n\t\t\t\t\t<span class="review-gallery-preview-icon">\n\t\t\t\t\t\t<a class="review-gallery-image-remove" href="#">\n\t\t\t\t\t\t\t<i class="mi delete"></i>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</span>\n\t\t\t\t</div>').css("background-image","url(".concat(e.target.result,")"));n(t).appendTo(i)},t.readAsDataURL(e.target.files[0])}}),n(".picture-field").on("click",".review-gallery-image-remove",function(e){e.preventDefault(),n('.picture-field input[type="file"]').val("").trigger("change")})}),jQuery(function(t){var i=t(".mylisting-register .primary-role-fields > .fields-wrapper"),n=t(".mylisting-register .secondary-role-fields > .fields-wrapper");"secondary"===t('.mylisting-register input[name="mylisting_user_role"]:checked').val()?i.detach():n.detach(),t('.mylisting-register input[name="mylisting_user_role"]').change(function(e){"secondary"===e.target.value?(i.detach(),n.appendTo(".mylisting-register .secondary-role-fields")):(n.detach(),i.appendTo(".mylisting-register .primary-role-fields")),t(e.target).addClass("role-active"),t(e.target).siblings().removeClass("role-active")})}),jQuery(function(t){t(".login-tabs a").click(function(e){e.preventDefault(),"register"===e.target.dataset.form?(t(".login-form-wrap").addClass("hide"),t(".register-form-wrap").removeClass("hide")):(t(".register-form-wrap").addClass("hide"),t(".login-form-wrap").removeClass("hide")),t(".login-tabs li").removeClass("active"),t(e.target).parents("li").addClass("active")}),t(".login-form-wrap").hasClass("hide")||t(".login-form-wrap #username").focus()}),window.cts_google_login=function(){gapi.load("auth2",function(){gapi.auth2.init(),jQuery(".cts-google-signin").each(function(e,i){var n=jQuery(".login-content");gapi.auth2.getAuthInstance().attachClickHandler(i,{},function(e){n.addClass("cts-processing-login"),jQuery.ajax({url:"".concat(CASE27.mylisting_ajax_url,"&action=cts_login_endpoint&security=").concat(CASE27.ajax_nonce),type:"POST",dataType:"json",data:{network:"google",token:e.getAuthResponse().id_token,process:"login",user_role:jQuery(i).parents("form").find('input[name="mylisting_user_role"]:checked').val()},success:function(e){if("error"===e.status&&e.message)return n.removeClass("cts-processing-login"),alert(e.message);var t=jQuery(i).parents("form").find('input[name="redirect"]').val();t?window.location.href=t:window.location.reload()},error:function(e,t,i){console.log("Failed",e,t,i),n.removeClass("cts-processing-login")}})})})})},jQuery(".cts-facebook-signin").click(function(i){i.preventDefault();var n=jQuery(".login-content");FB.login(function(e){e.authResponse&&(n.addClass("cts-processing-login"),jQuery.ajax({url:"".concat(CASE27.mylisting_ajax_url,"&action=cts_login_endpoint&security=").concat(CASE27.ajax_nonce),type:"POST",dataType:"json",data:{network:"facebook",token:e.authResponse.accessToken,process:"login",user_role:jQuery(i.target).parents("form").find('input[name="mylisting_user_role"]:checked').val()},success:function(e){if("error"===e.status&&e.message)return n.removeClass("cts-processing-login"),alert(e.message);var t=jQuery(i.target).parents("form").find('input[name="redirect"]').val();t?window.location.href=t:window.location.reload()},error:function(e,t,i){console.log("Failed",e,t,i),n.removeClass("cts-processing-login")}}))},{scope:"public_profile,email"})})});
