function p(){const c=document.getElementById("title"),l=document.getElementById("ticket-suggestions");if(!c||!l)return;const d=window.ticketSuggestionsConfig||{},u=d.endpoint,r=d.translations||{};if(!u)return;let m=null,g="",a=null;function b(t){const e=t.kb||[],o=t.announcements||[];if(e.length===0&&o.length===0){l.innerHTML="",l.classList.add("d-none");return}let n=`
            <div class="card border-0 shadow-sm mt-2 ticket-suggestions-card">
                <div class="card-body p-3">
                    <div class="d-flex align-items-center mb-2">
                        <i class="fas fa-lightbulb text-warning me-2"></i>
                        <small class="fw-semibold text-muted">${i(r.heading||"Suggestions")}</small>
                    </div>
        `;if(e.length>0){n+=`<div class="mb-2"><small class="text-muted text-uppercase">${i(r.kb||"Knowledge Base")}</small></div>`,n+='<div class="list-group list-group-flush mb-2">';for(const s of e)n+=`
                    <a href="${f(s.url)}" target="_blank" rel="noopener" class="list-group-item list-group-item-action px-2 py-2 border-0 rounded mb-1 suggestion-item">
                        <div class="fw-semibold small"><i class="fas fa-book me-1 text-info"></i>${i(s.title)}</div>
                        ${s.excerpt?`<div class="text-muted small mt-1">${i(s.excerpt)}</div>`:""}
                    </a>
                `;n+="</div>"}if(o.length>0){n+=`<div class="mb-2"><small class="text-muted text-uppercase">${i(r.announcements||"Announcements")}</small></div>`,n+='<div class="list-group list-group-flush">';for(const s of o)n+=`
                    <a href="${f(s.url)}" target="_blank" rel="noopener" class="list-group-item list-group-item-action px-2 py-2 border-0 rounded mb-1 suggestion-item">
                        <div class="fw-semibold small"><i class="fas fa-bullhorn me-1 text-warning"></i>${i(s.title)}</div>
                        ${s.excerpt?`<div class="text-muted small mt-1">${i(s.excerpt)}</div>`:""}
                    </a>
                `;n+="</div>"}n+=`
                </div>
            </div>
        `,l.innerHTML=n,l.classList.remove("d-none")}function i(t){return String(t??"").replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e])}function f(t){return i(t)}async function v(t){if(t.length<3){l.innerHTML="",l.classList.add("d-none");return}if(t!==g){g=t,a&&a.abort(),a=new AbortController;try{const e=await fetch(`${u}?q=${encodeURIComponent(t)}`,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"},signal:a.signal});if(!e.ok)return;const o=await e.json();b(o)}catch(e){e.name!=="AbortError"&&console.warn("ticket suggestions error",e)}}}c.addEventListener("input",function(){clearTimeout(m);const t=this.value.trim();m=setTimeout(()=>v(t),300)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",p):p();
