import{b as m,s as o,e as f,i as y,d as v,f as g}from"./index.02a5ed9a.js";import{m as t,b as E,t as b,s as S,c as C,d as _}from"./postContent.bb42e0a8.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(500)}),window.tinyMCE.get("content").on("paste",()=>{t(500)}))},50)}else{const a=document.querySelector("textarea#content");a&&(a.addEventListener("keyup",()=>{t(500)}),a.addEventListener("paste",()=>{t(500)}))}const n=document.querySelector("#post input#title");n&&n.addEventListener("input",()=>{t(500)});const i=document.querySelector("#post textarea#excerpt");i&&i.addEventListener("input",()=>{t(500)});const s=document.querySelector("#post_name");s&&s.addEventListener("change",()=>{t(500)});const c=document.querySelector("#edit-slug-buttons");c&&c.addEventListener("click",a=>{a.target===c.querySelector("#edit-slug-buttons button.save")&&t()});const d=document.querySelector("#categorychecklist");d&&d.addEventListener("change",function(){E()});const u=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(500)}),window.tinyMCE.get("content").on("paste",()=>{t(500)})}const p=document.querySelector("#content");p&&(p.addEventListener("keyup",()=>{t(500)}),p.addEventListener("paste",()=>{t(500)}))}})},l=new MutationObserver(u),r=document.querySelector("#wp-content-wrap");r&&l.observe(r,{attributes:!0}),setInterval(()=>{e&&(e=!1)},500),b()&&!m()&&(e=!0,setInterval(()=>{window.tinyMCE&&window.tinyMCE.activeEditor&&window.tinyMCE.activeEditor.isDirty()&&!e&&(e=!0,t())},500))},h=()=>{t(),window.wp.data.subscribe(()=>{t(500);const e=window.wp.data.select("core/editor").isSavingPost(),n=window.wp.data.select("core/editor").isAutosavingPost();e&&!n&&(o.commit("isDirty",!1),t())})},k=()=>{if(o.getters.isUnlicensed)return;let e="",n="",i="";window.addEventListener("change",s=>{if(s.target.tagName!=="INPUT")return;const c=document.getElementById("_sku");c&&(e=c.value),o.commit("live-tags/updateWooCommerceSku",e);const d=document.getElementById("_sale_price"),u=document.getElementById("_regular_price");d&&(n=d.value),!n&&u&&(n=u.value);const l=window.aioseo.data.wooCommerce.currencySymbol+parseFloat(n||0).toFixed(2);o.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?i!==r[0].parentNode.innerText&&(i=r[0].parentNode.innerText,o.commit("live-tags/updateWooCommerceBrand",r[0].parentNode.innerText)):i!==""&&(i="",o.commit("live-tags/updateWooCommerceBrand",""))})},q=(e,n=!0)=>{if(o.state.loaded||f(e,{}),!!S())if(t(),window.aioseo.currentPost.context==="term")C();else if(o.dispatch("ping"),n&&o.dispatch("savePostState"),y()){const i=window.setInterval(()=>{window.wp.data.select("core/editor").getCurrentPost().id&&(window.clearInterval(i),h())},50);window.addEventListener("beforeunload",s=>{o.state.isDirty&&(s.preventDefault(),s.returnValue="")})}else m()&&k(),(v()||g())&&x(),_()};export{q as l};
