import{E as L,e as y,j as N,F as A,u as q,i as W,y as U,z as $}from"./index.21ff19c6.js";import{s as z}from"./metabox.c14c3439.js";import{m as e,i as k,j as F,k as D,l as O}from"./SchemaStore.e1c60a5d.js";const j=()=>{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 c=document.querySelector("#edit-slug-buttons");c&&c.addEventListener("click",o=>{o.target===c.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()}})},a=new MutationObserver(u),s=document.querySelector("#wp-content-wrap");s&&a.observe(s,{attributes:!0});const p=document.querySelector("#wp-excerpt-wrap");p&&a.observe(p,{attributes:!0}),setInterval(()=>{t&&(t=!1)},500),F()&&!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)}))},R=()=>{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=N();return(t==null?void 0:t.isUnlicensed)||!1},f=()=>{var v,S,g,_,x,b,C,P,h;let t="",n="",i="",c=[],d=!1,u="";const a=A(),s=y(),p=document.getElementById("_sku");p&&(t=p.value,a.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=(v=q().aioseo.data)==null?void 0:v.wooCommerce)==null?void 0:S.currencySymbol)||"$"+parseFloat(n||0).toFixed(2);a.updateWooCommercePrice(T);const B=["pwb-brand","product_brand"];for(const r of B)if(c=document.querySelectorAll(`#post input[name="tax_input[${r}][]"]:checked`),!!c.length){if(i!==c[0].parentNode.innerText&&(i=c[0].parentNode.innerText,a.updateWooCommerceBrand(c[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&&a.updateWooCommerceBrand(w.parentNode.innerText)}d=!0;break}d||a.updateWooCommerceBrand("");const E=document.querySelectorAll('#post input[name="tax_input[product_cat][]"]:checked');if(E.length&&(u=E[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)||"")}a.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 G=()=>{M()||(window.addEventListener("change",t=>{t.target.tagName==="INPUT"&&f()}),window.aioseoBus.$on("standalone-update-post",t=>{t.primary_term&&f()}))},Q=(t,n=!0)=>{if(!z())return;e();const i=y();if(i.currentPost.context==="term")D();else if(q().ping(),n&&i.savePostState(),W()){const d=window.setInterval(()=>{window.wp.data.select("core/editor").getCurrentPost().id&&(window.clearInterval(d),R())},50)}else L()&&G(),(U()||$())&&j(),O()};export{Q as l};
