const i=document.querySelector("#main-widget-container"),u=1e3,n=()=>{const t={};document.querySelectorAll(".mt-widget--resizable").forEach((e,a)=>{t[e.id]={order:u+(a+1)/1e3,size:e.classList.contains("mt-widget--half")?"half":"full"}});const r=new FormData;r.append("__mode","update_widget_prefs"),r.append("widget_action","save_layout"),r.append("xhr","1"),r.append("magic_token",i.dataset.magicToken),r.append("widget_scope",i.dataset.currentWidgetScope),r.append("widget_layout",JSON.stringify(t)),fetch(window.CMSScriptURI,{method:"POST",body:r,headers:{"X-Requested-With":"XMLHttpRequest"}}).then(async e=>{const a=await e.json();if(a.error)throw new Error(a.error)}).catch(e=>{alert(e.message)})};let o=!1;jQuery(i).sortable({items:".mt-widget--resizable",handle:".mt-widget__title .mt-icon",placeholder:"placeholder",forcePlaceholderSize:!0,tolerance:"pointer",start:()=>{o=!0,jQuery(i).sortable("refreshPositions")},stop:()=>{o=!1},update:()=>{n()}}),document.querySelectorAll(".mt-widget--resizable").forEach(t=>{let r=!0,e;new ResizeObserver(a=>{if(r){r=!1;return}if(!o)for(const d of a)e===void 0&&window.addEventListener("mouseup",()=>{if(!e)return;const l=t.parentElement.clientWidth,c=e/l;e=void 0,setTimeout(()=>{t.style.width="";let s=!1;c>.7?t.classList.contains("mt-widget--half")&&(t.classList.remove("mt-widget--half"),s=!0):t.classList.contains("mt-widget--half")||(t.classList.add("mt-widget--half"),s=!0),s&&n()})},{once:!0,passive:!0}),e=d.contentRect.width}).observe(t)});
