"use strict";(globalThis.webpackChunkextendify=globalThis.webpackChunkextendify||[]).push([[405],{4539(t,e,n){var i=n(5859),r=n(7723);const o="extendify-agent-sidebar";function u(){const t=document.getElementById("wp-admin-bar-extendify-agent-btn");return t?t.querySelector("button")||t:null}function a(){const t=u();return!!t&&(t.click(),!0)}function d(t,e,n){return new Promise((i,r)=>{let o=0;const u=()=>t()?i():++o>=e?r():void setTimeout(u,n);u()})}function s(){if((0,i.n)())return;const t=document.getElementById("extendify-toolbar");if(!t)return;const e=document.getElementById("ext-tb-ai-agent"),n=document.getElementById("ext-tb-quick-edit");e&&(e.disabled=!0,e.title=(0,r.__)("Loading…","extendify-local"),e.setAttribute("aria-busy","true"),d(u,100,50).then(()=>{e.disabled=!1,e.removeAttribute("title"),e.setAttribute("aria-busy","false")},()=>{e.title=(0,r.__)("AI Agent unavailable","extendify-local"),e.setAttribute("aria-busy","false")}),e.addEventListener("click",t=>{t.preventDefault(),a()||d(u,20,50).then(a)})),n&&(function(t){const e=()=>{const e=document.documentElement.classList.contains("extendify-quick-edit-on");t.setAttribute("aria-checked",e?"true":"false")};e(),new MutationObserver(e).observe(document.documentElement,{attributes:!0,attributeFilter:["class"]})}(n),n.addEventListener("click",t=>{t.preventDefault(),window.dispatchEvent(new CustomEvent("extendify-quick-edit:toggle"))})),function(t,e){let n=!1;const i=new MutationObserver(()=>{const i=document.getElementById(o);if(!i||n)return;n=!0;const r=()=>{const n=!i.hasAttribute("inert");t.classList.toggle("ext-tb-agent-open",n),e&&(e.inert=n,n?(e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","true")):(e.removeAttribute("tabindex"),e.removeAttribute("aria-hidden")))};new MutationObserver(r).observe(i,{attributes:!0,attributeFilter:["inert"]}),r()});i.observe(document.body,{childList:!0,subtree:!0}),document.getElementById(o)&&i.takeRecords()}(t,e)}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",s):s()},7723(t){t.exports=window.wp.i18n}},t=>{t.O(0,[223],()=>t(t.s=4539)),t.O()}]);