import{m as t,ag as v,ah as h,ae as g,u as y,h as P,ai as k,b as _,af as I,aj as L,i as q,H as B,I as M,ak as T}from"./app-core.3e3b5f4b.js";const N=()=>{let e=!1;if(document.querySelector("#wp-content-wrap.tmce-active")){const n=window.setInterval(()=>{!window.tinyMCE||!window.tinyMCE.activeEditor||(window.clearInterval(n),t(),window.tinyMCE.get("content").on("keyup",()=>{t(500)}),window.tinyMCE.get("content").on("paste",()=>{t(500)}))},50)}else{const n=document.querySelector("textarea#content");n&&(n.addEventListener("keyup",()=>{t(500)}),n.addEventListener("paste",()=>{t(500)}))}const o=document.querySelector("#post input#title");o&&o.addEventListener("input",()=>{t(500)}),S();const r=document.querySelector("#post_name");r&&r.addEventListener("change",()=>{t(500)});const i=document.querySelector("#edit-slug-buttons");i&&i.addEventListener("click",n=>{n.target===i.querySelector("#edit-slug-buttons button.save")&&t()});const d=document.querySelector("#categorychecklist");d&&d.addEventListener("change",function(){v()}),window.aioseoBus.$on("standalone-update-post",n=>{n.primary_term&&v()});const u=function(n){n.forEach(l=>{if(l.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 m=document.querySelector("#content");m&&(m.addEventListener("keyup",()=>{t(500)}),m.addEventListener("paste",()=>{t(500)})),S()}})},a=new MutationObserver(u),c=document.querySelector("#wp-content-wrap");c&&a.observe(c,{attributes:!0});const p=document.querySelector("#wp-excerpt-wrap");p&&a.observe(p,{attributes:!0}),setInterval(()=>{e&&(e=!1)},500),h()&&!g()&&(e=!0,setInterval(()=>{window.tinyMCE&&window.tinyMCE.activeEditor&&window.tinyMCE.activeEditor.isDirty()&&!e&&(e=!0,t())},500))},S=()=>{if(document.querySelector("#wp-excerpt-wrap.tmce-active")){const o=window.setInterval(()=>{window.tinyMCE&&(window.clearInterval(o),t(),window.tinyMCE.get("excerpt").on("keyup",()=>{t(500)}),window.tinyMCE.get("excerpt").on("paste",()=>{t(500)}))},50)}const e=document.querySelector("#post textarea#excerpt");e&&(e.addEventListener("keyup",()=>{t(500)}),e.addEventListener("paste",()=>{t(500)}))},A=()=>{t(),window.wp.data.subscribe(()=>{t(500);const e=window.wp.data.select("core/editor").isSavingPost(),o=window.wp.data.select("core/editor").isAutosavingPost();if(e&&!o){const r=y();r.isDirty=!1,t()}})},b=()=>P()?.isUnlicensed||!1,w=()=>{let e="",o="",r="",i=[],d=!1,u="";const a=k(),c=y(),p=document.getElementById("_sku");p&&(e=p.value,a.updateWooCommerceSku(e));const n=document.getElementById("_sale_price"),l=document.getElementById("_regular_price");n&&(o=n.value),!o&&l&&(o=l.value);const x=_().aioseo.data?.wooCommerce?.currencySymbol||"$"+parseFloat(o||0).toFixed(2);a.updateWooCommercePrice(x);const C=["pwb-brand","product_brand"];for(const s of C)if(i=document.querySelectorAll(`#post input[name="tax_input[${s}][]"]:checked`),!!i.length){if(r!==i[0].parentNode.innerText&&(r=i[0].parentNode.innerText,a.updateWooCommerceBrand(i[0].parentNode.innerText)),c.currentPost?.primary_term?.[s]){const E=document.querySelector(`#${s}checklist input[value="${c.currentPost.primary_term[s]}"]`);E?.parentNode?.innerText&&a.updateWooCommerceBrand(E.parentNode.innerText)}d=!0;break}d||a.updateWooCommerceBrand("");const f=document.querySelectorAll('#post input[name="tax_input[product_cat][]"]:checked');if(f.length&&(u=f[0].parentNode.innerText),c.currentPost?.primary_term?.product_cat){const s=document.getElementById(`in-product_cat-${c.currentPost.primary_term.product_cat}`)||document.getElementById(`in-product_cat-${c.currentPost.primary_term.product_cat}-1`);u=s?.childNodes[0]?.innerText||"",s.hasChildNodes()||(u=s?.parentNode?.innerText||"")}a.updateTaxonomyTitle(u)};window.addEventListener("DOMContentLoaded",()=>{window?.aioseo?.screen?.base!=="customize"&&!b()&&w()});const W=()=>{b()||(window.addEventListener("change",e=>{e.target.tagName==="INPUT"&&w()}),window.aioseoBus.$on("standalone-update-post",e=>{e.primary_term&&w()}))},$=(e,o=!0)=>{if(!I())return;t();const r=y();if(r.currentPost.context==="term")(document.querySelector("#edittag")||{})?.addEventListener("submit",()=>{r.isDirty=!1}),L();else if(_().ping(),o&&r.savePostState(),q()){const d=window.setInterval(()=>{window.wp.data.select("core/editor").getCurrentPost().id&&(window.clearInterval(d),A())},50)}else g()&&W(),(B()||M())&&((document.querySelector("#post")||{})?.addEventListener("submit",()=>{r.isDirty=!1}),N()),T()};export{$ as l};
