import{H as e,Y as k,Z as N,W as L,F as y,j as A,_ as W,u as q,X as $,$ as U,i as F,I as z,J as D,a0 as O}from"./index.bd66e758.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)}),I();const i=document.querySelector("#post_name");i&&i.addEventListener("change",()=>{e(500)});const a=document.querySelector("#edit-slug-buttons");a&&a.addEventListener("click",o=>{o.target===a.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)})),I()}})},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()&&!L()&&(t=!0,setInterval(()=>{window.tinyMCE&&window.tinyMCE.activeEditor&&window.tinyMCE.activeEditor.isDirty()&&!t&&(t=!0,e())},500))},I=()=>{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)}))},j=()=>{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 i=y();i.isDirty=!1,e()}})},M=()=>{const t=A();return(t==null?void 0:t.isUnlicensed)||!1},f=()=>{var E,S,g,_,x,b,C,P,h;let t="",n="",i="",a=[],d=!1,u="";const c=W(),s=y(),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 r of B)if(a=document.querySelectorAll(`#post input[name="tax_input[${r}][]"]:checked`),!!a.length){if(i!==a[0].parentNode.innerText&&(i=a[0].parentNode.innerText,c.updateWooCommerceBrand(a[0].parentNode.innerText)),(_=(g=s.currentPost)==null?void 0:g.primary_term)!=null&&_[r]){const w=document.querySelector(`#${r}checklist input[value="${s.currentPost.primary_term[r]}"]`);(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 r=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=r==null?void 0:r.childNodes[0])==null?void 0:P.innerText)||"",r.hasChildNodes()||(u=((h=r==null?void 0:r.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()&&f()});const H=()=>{M()||(window.addEventListener("change",t=>{t.target.tagName==="INPUT"&&f()}),window.aioseoBus.$on("standalone-update-post",t=>{t.primary_term&&f()}))},X=(t,n=!0)=>{if(!$())return;e();const i=y();if(i.currentPost.context==="term")U();else if(q().ping(),n&&i.savePostState(),F()){const d=window.setInterval(()=>{window.wp.data.select("core/editor").getCurrentPost().id&&(window.clearInterval(d),j())},50)}else L()&&H(),(z()||D())&&R(),O()};export{X as l};
