!function(){"use strict";document.addEventListener("DOMContentLoaded",(()=>(()=>{const t=document.querySelector(".user-profile-picture"),e=document.querySelector(".wpmastertoolkit-local-avatars");if(t&&e){(()=>{const a=e.querySelector("tr");t.innerHTML=a.innerHTML,e.remove()})();const a=document.querySelector("#wpmastertoolkit-local-avatar-icon-preview-container"),s=document.querySelector("#wpmastertoolkit-local-avatar-icon-preview"),i=document.querySelector("#wpmastertoolkit_local_avatar_icon_hidden_field"),r=document.querySelector("#wpmastertoolkit-local-avatar-choose-from-library-button"),o=document.querySelector("#wpmastertoolkit-js-remove-local-avatar-icon");let c;const l=t=>{if(s.src=t.url,a.classList.remove("hidden"),o.classList.remove("hidden"),"1"!==r.getAttribute("data-state")){const t=r.getAttribute("data-alt-classes");r.setAttribute("class",t),r.setAttribute("data-alt-classes",r.className),r.setAttribute("data-state","1")}r.textContent=r.getAttribute("data-update-text")},n=t=>{let e,a,s,i=t.get("width"),r=t.get("height"),o=100,c=100,l=o/c,n=o,d=c;return i/r>l?(c=r,o=c*l):(o=i,c=o/l),e=(i-o)/2,a=(r-c)/2,s={aspectRatio:o+":"+c,handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:i,imageHeight:r,minWidth:n>o?o:n,minHeight:d>c?c:d,x1:e,y1:a,x2:o+e,y2:c+a},s};r.addEventListener("click",(t=>{const e=t.currentTarget;c=wp.media({button:{text:e.dataset.update,close:!1},states:[new wp.media.controller.Library({title:e.dataset.chooseText,library:wp.media.query({type:"image"}),date:!1,suggestedWidth:e.dataset.size,suggestedHeight:e.dataset.size}),new wp.media.controller.Cropper({control:{params:{width:e.dataset.size,height:e.dataset.size}},imgSelectOptions:n})]}),c.on("cropped",(function(t){i.value=t.id||t.attachment_id,l(t),c.close(),c=null})),c.on("select",(function(){let t=c.state().get("selection").first();t.attributes.height==e.dataset.size&&e.dataset.size==t.attributes.width?(l(t.attributes),c.close(),i.value=t.id||t.attachment_id):c.setState("cropper")})),c.open()})),o.addEventListener("click",(function(t){const e=t.currentTarget;i.value="false",e.classList.toggle("hidden"),a.classList.toggle("hidden"),s.src="",s.alt="",r.className=r.getAttribute("data-alt-classes"),r.setAttribute("data-alt-classes",r.className),r.setAttribute("data-state",""),r.textContent=r.getAttribute("data-choose-text"),r.focus()}))}})()))}();