import{REDOCLY_TEAMS_RBAC as l}from"@redocly/config";import{prepareSearchDocuments as m}from"./documents/search-documents.js";import{SearchEngine as f}from"./engines/search-engine.js";import{DEFAULT_SEARCH_ENGINE as i}from"./constants.js";import{isDevelopMode as E}from"../../utils/is-develop-mode.js";import{prepareAiSearchDocuments as p}from"./ai-indexer/prepare-ai-search-documents.js";import{isAiSearchEnabled as d}from"./utils.js";async function _(){let e=!0;return{async afterRoutesCreated(r,a){(process.env.SEARCH_DEV_REINIT||e)&&await S(r,a),e=!1},id:"search"}}async function S(e,r){const a=e.getConfig(),c=a.search?.engine||i,s=E()?process.env.SEARCH_DEV_DEBUG?c:i:c,{l10n:h}=e.getGlobalData(),o=d(a),n=a.rbac?.features?.aiSearch,t=new f(s,h);await t.initIndexSchema(e.getSearchFacets()),e.setSearchEngine(t),e.setGlobalData({searchFeatures:{advanced:{enabled:s!==i&&!a.search?.filters?.hide},ai:{enabled:o,[l]:n&&Object.keys(n).length?n:void 0}}}),await m(r.fs,e,t),await p(e,r,{aiSearchEnabled:o,llmstxtEnabled:a.seo?.llmstxt?.hide!==!0})}export{_ as searchPlugin};
