jQuery(function(e){var r={init:function(){this.init_event()},profile_picture_upload:function(r){var t=user_registration_params.ajax_url+"?action=user_registration_profile_pic_upload&security="+user_registration_params.user_registration_profile_picture_upload_nonce,i=new FormData,a=r;i.append("file",a[0].files[0]);var o=a.closest(".button-group").find(".user_registration_profile_picture_upload"),n=o.text();e.ajax({url:t,data:i,type:"POST",processData:!1,contentType:!1,beforeSend:function(){o.text(user_registration_params.user_registration_profile_picture_uploading)},complete:function(e){var r="",t="";a.val("");var i=JSON.parse(e.responseText);r=i.data.message,i.success||(r='<p class="uraf-profile-picture-error user-registration-error">'+r+"</p>"),i.success&&(r="",t=i.data.url,i.data.attachment_id,upload_files=i.data.upload_files,a.closest(".button-group").find("#profile_pic_url").val(upload_files),a.closest(".user-registration-profile-header").find(".profile-preview").attr("src",t)),a.closest(".button-group").find(".profile-pic-remove").data("attachment-id",i.data.attachment_id),a.closest(".button-group").find(".profile-pic-remove").prop("style",!1),a.closest(".button-group").find(".user_registration_profile_picture_upload").attr("style","display:none"),a.closest(".user-registration-profile-header").find(".user-registration-profile-picture-error").remove(),a.closest(".button-group").after('<span class="user-registration-profile-picture-error">'+r+"</span>"),o.text(n)}})},init_event:function(){e(".user_registration_profile_picture_upload").on("click",function(){e(this).closest(".button-group").find('input[type="file"]').trigger("click")}),e(document).on("change",'.button-group input[type="file"]',function(){r.profile_picture_upload(e('.button-group input[type="file"]'))})},remove_avatar:function(e){var r=e.data("attachment-id");if(e.closest("form").find(".ur_removed_profile_pic").length<=0){var t=document.createElement("input");t.setAttribute("type","hidden"),t.setAttribute("class","ur_removed_profile_pic"),t.setAttribute("name","ur_removed_profile_pic"),t.setAttribute("value",""),e.closest("form").append(t)}var i=e.closest("form").find(".ur_removed_profile_pic").val(),a=new Set(i?JSON.parse(i):[]);a.add(r),e.closest("form").find(".ur_removed_profile_pic").val(JSON.stringify(Array.from(a)));e.closest("form").find('input[name="profile-pic"]');input_hidden=e.closest("form").find('input[name="profile-pic-url"]'),profile_default_input_hidden=e.closest("form").find('input[name="profile-default-image"]'),preview=e.closest("form").find("img.profile-preview"),input_hidden.val(""),preview.attr("src",profile_default_input_hidden.val()),e.hide(),e.closest(".button-group").find(".user_registration_profile_picture_upload").show(),e.closest(".user-registration-profile-header").find(".user-registration-profile-picture-error").remove()}};e(".profile-pic-remove, .uraf-profile-picture-remove").on("click",function(t){t.preventDefault(),r.remove_avatar(e(this))}),e(document).on("user_registration_frontend_before_edit_profile_submit",function(r,t,i){var a=e(".ur_removed_profile_pic");e.each(a,function(){t.ur_removed_profile_pic=e(this).val()})}),e(document).on("click","input#user_registration_user_email + div.email-updated.inline a",function(r){r.preventDefault();var t=e(this),i=new URL(r.target.href),a=i.searchParams.get("cancel_email_change"),o=i.searchParams.get("_wpnonce"),n=user_registration_params.ajax_url;e.ajax({type:"POST",url:n,data:{action:"user_registration_cancel_email_change",cancel_email_change:a,_wpnonce:o},success:function(e){e.success&&t.parents("div.email-updated.inline").remove()}})}),e(".ur-frontend-form").find(".user-registration-profile-header").find(".uraf-profile-picture-upload").length||(r.init(),e(".edit-profile").on("submit",function(r){var t=e(".ur-smart-phone-field");if("true"===t.attr("aria-invalid")){r.preventDefault();var i=t.closest("p.form-row");i.find("#"+t.data("id")+"-error").remove();var a='<label id="'+t.data("id")+'-error" class="user-registration-error" for="'+t.data("id")+'">'+user_registration_params.message_validate_phone_number+"</label>";return i.append(a),i.find("#"+t.data("id")).attr("aria-invalid",!0),!0}if(1===e(this).find(".user-registration-profile-picture-error").find(".user-registration-error").length)return r.preventDefault(),!0})),e("input.flatpickr-input").each(function(){e(this).val(e(this).attr("value"))})});