import{aY as q,aI as i,dH as P,o as l,W as S,r as y,a as x,co as L,v as O,ao as d,ap as k,a_ as w,a$ as b}from"./app-k0jcl5PQ.js";import{S as C}from"./BwBaQklX.chunk.js";function E(e){const{query:a,indices:c,analyticsOptions:s,onLog:u,shouldLog:g=!0}=e,f=q(a,5e3),[m,t]=i.useState({[a]:!1});function n(r,h){if(g){if(!r){t({"":!0});return}m[r]||(t({[r]:!0}),l.logUserAction({query:r,indices:c},l.mergeOptions(s,[{actionType:y.Search,workflowPhase:S.Complete},h])),typeof u=="function"&&u())}}function o(r,h){const N=r.name;m[N]||(t({[N]:!0}),l.logUserAction(r,l.mergeOptions(s,[{actionType:y.Search,workflowPhase:S.Complete},h])))}return i.useEffect(()=>n(f),[f]),P(()=>n(a),[a,m]),{log:n,logTrendingTopic:o}}const I="_searchSvg_1f2uy_1",A="_searchInput_1f2uy_7",v={searchSvg:I,searchInput:A};T.defaultProps={debounceTime:300,queryParamName:"query"};function T(e){const a=x.getCurrentRoute().appLink.params,[c,s]=i.useState((a==null?void 0:a[e.queryParamName])??"");i.useEffect(()=>{var t,n;if(a){if(a[e.queryParamName]){s(((t=a[e.queryParamName])==null?void 0:t.trim())??"");return}c.length&&!((n=a[e.queryParamName])!=null&&n.length)&&s("")}},[e.id]),i.useEffect(()=>{a!=null&&a[e.queryParamName]&&(a==null?void 0:a[e.queryParamName])!==c&&s(a==null?void 0:a[e.queryParamName])},[a==null?void 0:a[e.queryParamName]]);const u=q(c,e.debounceTime);i.useEffect(()=>{f(u)},[u]);function g(t){s(t.target.value)}function f(t=""){if(t===a[e.queryParamName]||!t&&!a[e.queryParamName])return;const n=L.omit(a,[e.queryParamName,"cursor"]),o={[e.queryParamName]:t.trim()?t.trimLeft():"",...n};o[e.queryParamName]||(delete o[e.queryParamName],delete o.cursor),C.preventScrollTop(),e.analyticsOptions&&l.logUserAction({query:t,indices:e.searchIndices},l.mergeOptions(e.analyticsOptions,{actionType:y.InstantSearch,workflowPhase:S.Complete})),O.trigger({...e.searchAppLink,params:o})}const{log:m}=E({query:c,indices:e.searchIndices,analyticsOptions:e.analyticsOptions,shouldLog:!!e.analyticsOptions});return d.jsxs("div",{className:"position-relative w-100",children:[d.jsx("input",{name:e.name,type:"text",className:k(`form-control pe-2 w-100 border-dark ${v.searchInput}`,e.size==="lg"&&"form-control-lg",e.className),id:e.id,autoComplete:"off",placeholder:e.placeholder,"aria-label":"Search",onChange:g,onBlur:t=>m(t.target.value??""),value:c}),d.jsx(w,{svg:b,className:`${v.searchSvg} svg-container cursor-pointer text-dark`})]})}export{T as S};
//# sourceMappingURL=DC-kGY5u.chunk.js.map
