import{getContext as e,getElement as t,store as r}from"@wordpress/interactivity";let n=!1;r("site-reviews/surecart-product-rating",{state:{get formattedText(){const t=e();return t.textTemplate?.replace("{num}",t.reviewCount||0)||"0"}},actions:{scroll(e){(e=>{const t=window.location,r=new URL(e,t);if(r.origin===t.origin&&r.pathname===t.pathname&&r.hash){const e=document.getElementById(r.hash.slice(1));if(e)return e.scrollIntoView({behavior:"smooth"}),!0}return!1})(e.target.href)&&e.preventDefault()}},callbacks:{init(){if(n)return;n=!0;const r=e(),{ref:o}=t();GLSR.Event.on("site-reviews/form/handle",({summary:e})=>{if(!e||!o)return;const t=(new DOMParser).parseFromString(e,"text/html").body.querySelector(".glsr-star-rating");if(!t)return;const n=o.querySelector(".glsr-star-rating");if(!n)return;const s=t.dataset.reviews??"0";n.replaceWith(t),r.reviewCount=parseInt(s,10)||0,console.log(r)})}}});