import{withPathPrefix as f}from"@redocly/theme/core/utils";import{ServerRoutes as d}from"../../../../../../constants/api.js";import{DEFAULT_LOCALE_PLACEHOLDER as m}from"../../../../../../constants/common.js";const y=async(i,t)=>{const{query:c,product:l,locale:u}=i,p=t.config.l10n?.defaultLocale||m,h=JSON.stringify({query:c,product:l,locale:u||p});let e=`${t.baseUrl}${f(d.SEMANTIC_SEARCH)}`;e.startsWith("http://")&&(e=e.replace(/^http:\/\//,"https://"));const o=t.accessToken?`authorization=${String(t.accessToken).replace(/^Bearer /,"")}`:"";try{const s=await fetch(e,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",...o?{Cookie:o}:{}},body:h});if(!s.ok)return{content:[{type:"text",text:"Error retrieving search results."}],isError:!0};const r=await s.json();if(!r||r.length===0)return{content:[{type:"text",text:"No results found."}]};const a=r.map(n=>`### [${n.title}](${new URL(n.url,t.baseUrl).toString()})

${n.content}
`).join(`

`).trim();return{content:[{type:"text",text:a.length?a:"No results found."}]}}catch{return{content:[{type:"text",text:"Error retrieving search results."}],isError:!0}}};var C={search:y};export{C as default};
