import{useCallback as g,useEffect as m,useRef as f}from"react";import{useCatalogEntityDetails as d}from"@redocly/theme/core/hooks";import{usePageProps as p}from"../../../providers/hooks.js";import{telemetry as c}from"../../telemetry/index.js";const l={id:"redocly-unknown",object:"catalog_entity",uri:"redocly-unknown"},C={entities:"catalog_entity",related_entities:"catalog_entity"},E={entities:({items:e,searchQuery:n})=>{const t=e[0]??l;c.sendCatalogEntitiesListSearchQueryMessage([{query:n,...t}])},related_entities:({items:e,searchQuery:n})=>{const t=e[0]??l;c.sendCatalogEntitiesRelatedEntitiesListSearchQueryMessage([{query:n,...t}])}};function j({isLoading:e,items:n,apiResource:t,searchQuery:i}){const{catalogConfig:u,entitiesCatalogConfig:y}=p(),o=f(i),{getEntityDetailsLink:s}=d({catalogConfig:u,entitiesCatalogConfig:y}),a=g(r=>({id:r.id,object:C[t],uri:s(r)}),[s,t]);m(()=>{if(e)return;const r=i?.trim();!r||r===o.current||(o.current=i,E[t]({items:n.map(a),searchQuery:i}))},[n,e,i,t,a])}export{j as useSearchTracker};
