!function(){"use strict";document.addEventListener("DOMContentLoaded",(()=>(()=>{const t=document.querySelector(".site-icon-section"),e=document.querySelector("#app-icon-preview"),s=document.querySelector("#browser-icon-preview"),i=document.querySelector("#js-remove-site-icon"),a=document.querySelector("#wpmastertoolkit-apple-touch-icon-preview"),r=wpmastertoolkit_apple_touch_icon.default_icon;if(t&&a){const c=document.querySelector("#wpmastertoolkit-app-icon-preview"),n=document.querySelector("#wpmastertoolkit_apple_touch_icon_hidden_field"),o=document.querySelector("#wpmastertoolkit-choose-from-library-button"),l=document.querySelector("#wpmastertoolkit-js-remove-site-icon");let d;(()=>{const e=a.closest("tr"),s=t.closest("tr");s.parentNode.insertBefore(e,s.nextSibling)})(),-1===e.src.indexOf("php")&&-1===e.src.indexOf("default")||(e.src=r,s.src=r),"false"!==n.value&&(e.src=c.src);const u=t=>{let s;if(s=t.alt?wp.i18n.sprintf(/* translators: %s: The selected image alt text. */
wp.i18n.__("App icon preview: Current image: %s"),t.alt):wp.i18n.sprintf(/* translators: %s: The selected image filename. */
wp.i18n.__("App icon preview: The current image has no alternative text. The file name is: %s"),t.filename),c.src=t.url,c.alt=s,e.src=t.url,e.alt=s,a.classList.remove("hidden"),l.classList.remove("hidden"),"1"!==o.getAttribute("data-state")){const t=o.getAttribute("data-alt-classes");o.setAttribute("class",t),o.setAttribute("data-alt-classes",o.className),o.setAttribute("data-state","1")}o.textContent=o.getAttribute("data-update-text")},p=t=>{let e,s,i,a=t.get("width"),r=t.get("height"),c=512,n=512,o=c/n,l=c,d=n;return a/r>o?(n=r,c=n*o):(c=a,n=c/o),e=(a-c)/2,s=(r-n)/2,i={aspectRatio:c+":"+n,handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:a,imageHeight:r,minWidth:l>c?c:l,minHeight:d>n?n:d,x1:e,y1:s,x2:c+e,y2:n+s},i};o.addEventListener("click",(t=>{const e=t.currentTarget;d=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.SiteIconCropper({control:{params:{width:e.dataset.size,height:e.dataset.size}},imgSelectOptions:p})]}),d.on("cropped",(function(t){n.value=t.id,u(t),d.close(),d=null})),d.on("select",(function(){let t=d.state().get("selection").first();t.attributes.height==e.dataset.size&&e.dataset.size==t.attributes.width?(u(t.attributes),d.close(),n.value=t.id):d.setState("cropper")})),d.open()})),l.addEventListener("click",(function(t){const i=t.currentTarget;e.classList.remove("hidden"),n.value="false",i.classList.toggle("hidden"),a.classList.toggle("hidden"),c.src="",c.alt="",e.src=s.src;let r=o.getAttribute("data-alt-classes"),l=o.className;o.setAttribute("class",r),o.setAttribute("data-alt-classes",l),o.setAttribute("data-state",""),o.textContent=o.getAttribute("data-choose-text"),o.focus()})),i.addEventListener("click",(function(t){s.src=r,""!==c.src&&-1===c.src.indexOf("php")?e.src=c.src:e.src=r})),s.addEventListener("load",(function(){""!==c.src&&-1===c.src.indexOf("php")&&(e.src=c.src)}))}})()))}();