import{a as i,T as f}from"./index.0f8634bc.js";import{v as t,w as y,u as v,a as m,s as g,x as E,i as S,b,y as _}from"./helpers.a4115088.js";const x=()=>{let e=!1;if(document.querySelector("#wp-content-wrap.tmce-active")){const a=window.setInterval(()=>{!window.tinyMCE||!window.tinyMCE.activeEditor||(window.clearInterval(a),t(),window.tinyMCE.get("content").on("keyup",()=>{t(2e3)}),window.tinyMCE.get("content").on("paste",()=>{t(2e3)}))},50)}else{const a=document.querySelector("textarea#content");a&&(a.addEventListener("keyup",()=>{t(2e3)}),a.addEventListener("paste",()=>{t(2e3)}))}const n=document.querySelector("#post input#title");n&&n.addEventListener("input",()=>{t(2e3)});const o=document.querySelector("#post textarea#excerpt");o&&o.addEventListener("input",()=>{t(2e3)});const u=document.querySelector("#post_name");u&&u.addEventListener("change",()=>{t(2e3)});const s=document.querySelector("#edit-slug-buttons");s&&s.addEventListener("click",a=>{a.target===s.querySelector("#edit-slug-buttons button.save")&&t()});const c=document.querySelector("#categorychecklist");c&&c.addEventListener("change",function(){y()});const d=function(a){a.forEach(w=>{if(w.attributeName==="class"){if(document.querySelector("#wp-content-wrap.tmce-active")){if(!window.tinyMCE)return;window.tinyMCE.get("content").on("keyup",()=>{t(2e3)}),window.tinyMCE.get("content").on("paste",()=>{t(2e3)})}const p=document.querySelector("#content");p&&(p.addEventListener("keyup",()=>{t(2e3)}),p.addEventListener("paste",()=>{t(2e3)}))}})},l=new MutationObserver(d),r=document.querySelector("#wp-content-wrap");r&&l.observe(r,{attributes:!0}),setInterval(()=>{e&&(e=!1)},2e3),v()&&!m()&&(e=!0,setInterval(()=>{window.tinyMCE&&window.tinyMCE.activeEditor&&window.tinyMCE.activeEditor.isDirty()&&!e&&(e=!0,t())},1500))},C=()=>{t(),window.wp.data.subscribe(()=>{t(2e3);const e=window.wp.data.select("core/editor").isSavingPost(),n=window.wp.data.select("core/editor").isAutosavingPost();e&&!n&&(i.commit("isDirty",!1),t())})},h=()=>{if(i.getters.isUnlicensed)return;let e="",n="",o="";window.addEventListener("change",u=>{if(u.target.tagName!=="INPUT")return;const s=document.getElementById("_sku");s&&(e=s.value),i.commit("live-tags/updateWooCommerceSku",e);const c=document.getElementById("_sale_price"),d=document.getElementById("_regular_price");c&&(n=c.value),!n&&d&&(n=d.value);const l=window.aioseo.data.wooCommerce.currencySymbol+parseFloat(n||0).toFixed(2);i.commit("live-tags/updateWooCommercePrice",l);let r=document.querySelectorAll('#post input[name="tax_input[product_brand][]"]:checked');r.length||(r=document.querySelectorAll('#post input[name="tax_input[pwb-brand][]"]:checked')),r.length?o!==r[0].parentNode.innerText&&(o=r[0].parentNode.innerText,i.commit("live-tags/updateWooCommerceBrand",r[0].parentNode.innerText)):o!==""&&(o="",i.commit("live-tags/updateWooCommerceBrand",""))})};var I=(e=!0)=>{if(i.state.loaded||f({}),!!g())if(t(),window.aioseo.currentPost.context==="term")E();else if(i.dispatch("ping"),e&&i.dispatch("savePostState"),S()){const n=window.setInterval(()=>{window.wp.data.select("core/editor").getCurrentPost().id&&(window.clearInterval(n),C())},50);window.addEventListener("beforeunload",o=>{!i.state.isDirty||(o.preventDefault(),o.returnValue="")})}else m()&&h(),b()&&x(),_()};export{I as l};
