(()=>{"use strict";document.addEventListener("DOMContentLoaded",(()=>{const e='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="snippet-copy-block__copy-icon"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>',t='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="snippet-copy-block__copy-icon"><polyline points="20 6 9 17 4 12"/></svg>',o=2e3;function n(e){return navigator.clipboard&&navigator.clipboard.writeText?navigator.clipboard.writeText(e).then((()=>!0)).catch((()=>c(e))):Promise.resolve(c(e))}function c(e){const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),t.select();let o=!1;try{o=document.execCommand("copy")}catch(e){o=!1}return document.body.removeChild(t),o}document.querySelectorAll(".wp-block-bpsc-snippet-copy-section").forEach((function(c){c.querySelectorAll(".snippet-copy-block__copy-button").forEach((i=>{const s=i.dataset.snippetIndex,p=c.querySelector('.snippet-copy-block__code-content[data-snippet-index="'+s+'"]');if(!p)return;const r=i.querySelector(".snippet-copy-block__copy-label"),l=r?r.textContent:"Copy";i.addEventListener("click",(()=>{n(p.textContent||"").then((n=>{n&&function(n,c){const i=n.querySelector(".snippet-copy-block__copy-label"),s=n.querySelector(".snippet-copy-block__copy-icon-wrap");n.classList.add("is-copied"),s&&(s.innerHTML=t),i&&(i.textContent="Copied!");const p=n.closest(".snippet-copy-block__card");if(p){const e=p.querySelector(".snippet-copy-block__toast");e&&e.remove();const t=document.createElement("div");t.className="snippet-copy-block__toast",t.textContent="Copied!",p.appendChild(t),setTimeout((()=>{t.parentNode&&t.remove()}),o)}setTimeout((()=>{n.classList.remove("is-copied"),s&&(s.innerHTML=e),i&&(i.textContent=c)}),o)}(i,l)}))}))}));const i=c.querySelector(".snippet-copy-block__copy-all-button");if(i){const s=i.querySelector(".snippet-copy-block__copy-label"),p=s?s.textContent:"Copy All";i.addEventListener("click",(()=>{const r=c.querySelectorAll(".snippet-copy-block__code-content");n(Array.from(r).map((e=>e.textContent||"")).join("\n\n")).then((n=>{if(n){const n=i.querySelector(".snippet-copy-block__copy-icon-wrap");i.classList.add("is-copied"),n&&(n.innerHTML=t),s&&(s.textContent="Copied All!"),setTimeout((()=>{i.classList.remove("is-copied"),n&&(n.innerHTML=e),s&&(s.textContent=p)}),o)}}))}))}}))}))})();