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