import{r as o,j as e}from"./iframe-p4aYZyoq.js";import{D as g}from"./dropdown-button-D0tG_Xmy.js";import{B as c}from"./button-BsNF7f-b.js";const x=i=>i.reduce((a,s)=>a+s.length,0),_=({searchTerm:i,namespaces:a={},onTextChange:s,onSubmit:u,onNamespaceChange:d,selectedNamespace:r,secondaryButtons:t,...h})=>{const p=o.useMemo(()=>({"--main-button-color":`var(--fr--color-${r}, var(--fr--color-sea-blue))`}),[r]),f=o.useMemo(()=>{const n=t&&x(t.map(({label:l})=>l));return n?{"--input-padding":`${n}ch`}:void 0},[t]),y=n=>e.jsx(c,{variant:"primary",style:p,onClick:n,children:a[r||Object.keys(a)[0]]});return e.jsxs("form",{onSubmit:u,"aria-label":"Main search",className:"main-search",children:[Object.keys(a).length>0&&d&&e.jsx(g,{visibleElement:y,propChangeToClose:r,children:e.jsx("ul",{className:"no-bullet",children:Object.keys(a).map(n=>e.jsx("li",{children:e.jsx(c,{variant:"tertiary",onClick:()=>{d(n)},children:a[n]})},n))})}),e.jsxs("div",{className:"main-search__input-container",children:[e.jsx("input",{type:"search","aria-label":`Text query${r?` in ${r}`:""}`,onChange:n=>s(n.target.value),value:i,style:f,...h}),t&&e.jsx("div",{className:"main-search__secondary-container",children:t.map(({label:n,action:l},m)=>e.jsxs(o.Fragment,{children:[m>0&&e.jsx("small",{children:" | "}),e.jsx("button",{type:"button",onClick:l,className:"main-search--secondary",children:e.jsx("small",{children:n})},n)]},m))})]}),e.jsx(c,{type:"submit",children:"Search"})]})};try{mainsearch.displayName="mainsearch",mainsearch.__docgenInfo={description:"",displayName:"mainsearch",props:{onSubmit:{defaultValue:null,description:"Action performed upon search submission",name:"onSubmit",required:!1,type:{name:"((e: SyntheticEvent<Element, Event>) => void) & FormEventHandler<HTMLInputElement>"}},onTextChange:{defaultValue:null,description:"What happens when text is typed in the search box",name:"onTextChange",required:!0,type:{name:"(selectedValue: string) => void"}},searchTerm:{defaultValue:null,description:"The search term",name:"searchTerm",required:!1,type:{name:"string"}},namespaces:{defaultValue:{value:"{}"},description:"An object representing the different namespace options",name:"namespaces",required:!1,type:{name:"Record<string, string>"}},onNamespaceChange:{defaultValue:null,description:"What happens when a namespace is changed in the dropdown",name:"onNamespaceChange",required:!1,type:{name:"((namespace: string) => void)"}},selectedNamespace:{defaultValue:null,description:"The selected namespace in the dropdown",name:"selectedNamespace",required:!1,type:{name:"string"}},secondaryButtons:{defaultValue:null,description:"A list of objects representing secondary buttons and their actions",name:"secondaryButtons",required:!1,type:{name:"{ label: string; action: () => void; }[]"}}}}}catch{}export{_ as M};
