import{gH as a,iP as q,iv as I,iY as M,ix as T,fH as n,bU as y,gZ as B,he as _,ej as L,dP as P}from"./strapi-ye6TfKul.js";const k=({disabled:o,label:m,placeholder:p,trackedEvent:c,trackedEventDetails:x})=>{const t=a.useRef(null),C=a.useRef(null),[{query:S},l]=q(),[r,i]=a.useState(S?._q||""),[u,f]=a.useState(!!r),{formatMessage:d}=I(),{trackUsage:j}=M(),g=T(),h=()=>f(e=>!e);a.useLayoutEffect(()=>{u&&t.current&&t.current.focus()},[u]);const v=()=>{i(""),l({_q:""},"remove")},R=e=>{e.preventDefault(),r?(c&&j(c,x),l({_q:encodeURIComponent(r),page:1})):(h(),l({_q:""},"remove"))},b=e=>n.jsx(L,{onSubmit:R,children:n.jsx(P,{ref:t,name:"search",onChange:s=>i(s.target.value),value:r,clearLabel:d({id:"clearLabel",defaultMessage:"Clear"}),onClear:v,placeholder:g?void 0:p,disabled:o,onBlur:e?.enableBlurClose?s=>{!s.currentTarget.contains(s.relatedTarget)&&s.currentTarget.value===""&&f(!1)}:void 0,children:m})});return g?n.jsx(y,{width:"100%",children:b()}):u?b({enableBlurClose:!0}):n.jsx(B,{ref:C,disabled:o,label:d({id:"global.search",defaultMessage:"Search"}),onClick:h,children:n.jsx(_,{})})};export{k as S};
