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