import{r as t,j as e,a4 as B,ad as O,av as v,au as C,af as P,O as R,o}from"./index-DR3HTfO6.js";import{S}from"./Search-DY52i3Q9.js";import{C as L}from"./Clear-DKF2FhrE.js";const T=t.createContext({}),{Provider:N}=T;function I({children:a}){const[n,s]=t.useState([]),[i,u]=t.useState([]),[l,p]=t.useState(!1),[x,r]=t.useState(!1),[b,c]=t.useState("Filter");return e.jsx(N,{value:{customButtons:n,setCustomButtons:s,customPreButtons:i,setCustomPreButtons:u,filterLabel:b,setFilterLabel:c,loading:l,setLoading:p,disabled:x,setDisabled:r},children:a})}function q(){return t.use(T)}function M({search:a="",options:n,searchText:s="",searchTextUpdate:i,searchClose:u,onSearchOpen:l=P}){const{searchOpen:p,searchPlaceholder:x,searchAlwaysOpen:r}=n,[b,c]=t.useState(!!s||p||!1),[f,w]=t.useState(s),j=t.useRef(null),{loading:g}=q(),{searchDebounceTime:d}=n,h=r||b,y=()=>{c(!0),l(!0)},F=k=>{const{value:m}=k.currentTarget;d?(clearTimeout(j.current),w(m),j.current=setTimeout(()=>{i(m)},d)):i(m)},$=()=>{c(!1),u(),w(""),l(!1)};return e.jsxs(D,{className:B({"search-always-open":r}),children:[h?e.jsx("div",{className:"toolbar-search-icon-placeholder",children:e.jsx(S,{})}):e.jsx(O,{title:a,disableFocusListener:!0,children:e.jsx(v,{"aria-label":a,"data-testid":`${a}-iconButton`,disabled:n.search==="disabled",onClick:y,children:e.jsx(S,{})})}),e.jsxs("div",{className:`toolbar-search-area ${h?"toolbar-btn-show":""}`,children:[h&&!g&&e.jsx(C,{variant:"standard",spacing:2,onChange:F,value:d?f:s,placeholder:x||"",autoFocus:!r}),g&&e.jsx(C,{disabled:!0,variant:"standard",spacing:2,value:d?f:s})]}),!r&&e.jsx("div",{className:`toolbar-search-close ${h?"toolbar-btn-show":""}`,children:e.jsx(v,{onClick:$,"aria-label":"click to close the search box",children:e.jsx(L,{})})})]})}M.propTypes={search:o.string,searchText:o.string,onSearchOpen:o.func,options:o.object.isRequired,searchTextUpdate:o.func.isRequired,searchClose:o.func.isRequired};const D=R("div")`
  display: flex;
  align-items: center;
  .toolbar-search-area {
    width: 0;
    transition: all ease 0.3s;
    overflow: hidden;
    .MuiFormControl-root {
      width: inherit;
      margin: 0 12px;
    }
    &.toolbar-btn-show {
      width: 260px;
      padding-left: 8px;

      ${a=>a.theme.breakpoints.down("md")} {
        width: 200px;
      }

      ${a=>a.theme.breakpoints.down("sm")} {
        width: 180px;
      }
      &.small-textfield {
        width: 200px;
      }
    }
  }
  .toolbar-search-close {
    width: 0;
    transition: all ease 0.3s;
    overflow: hidden;
    &.toolbar-btn-show {
      width: 40px;
    }
  }
  .toolbar-search-icon-placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
  }
  &.search-always-open {
    .MuiFormControl-root {
      margin: 0 12px 0 0;
    }
    .toolbar-btn-show {
      padding-left: 0;
    }
  }
`;export{M,I as P,q as p};
