import{r as n}from"./vendor-react-wBh_31cN.js";import{u as L,M as E,a as U,e as v}from"./Search-BDh3P0Yy.js";import{u as K}from"./useDebounce-BiuGz9t2.js";import{u as C}from"./useLazyInfiniteData-Bv3uuY8D.js";import{d as N}from"./vendor-router-D1GqFWiT.js";import{c as b}from"./time-utils-tK1noPML.js";import{o as T}from"./index-BKr2rJhV.js";import{a as S}from"./always-CtAmwIxm.js";const h=(e,a)=>{if(!e)return a;try{return JSON.parse(e)}catch(c){return console.warn("Failed to parse URL parameter:",e,c),a}},F=()=>{const[e,a]=N(),c=n.useCallback(s=>{a({...Object.fromEntries(e.entries()),match:e.getAll("match"),search:s})},[e,a]),i=n.useCallback((s,o,t)=>{const r=h(e.get("tags"),[{name:"",key:"",value:""}]).map((P,A)=>A!==o?P:s==="name"?{name:t,key:"",value:""}:s==="key"?{...P,key:t,value:""}:{...P,value:t}),y=new URLSearchParams(e);r.length===1&&!r[0].name&&!r[0].key&&!r[0].value?y.delete("tags"):y.set("tags",JSON.stringify(r)),a(y)},[e,a]),l=n.useCallback(()=>{const o=[...h(e.get("tags"),[]),{name:"",key:"",value:""}],t=new URLSearchParams(e);t.set("tags",JSON.stringify(o)),a(t)},[e,a]),d=n.useCallback(s=>{const o=h(e.get("tags"),[]);if(o.length===1){const r=new URLSearchParams(e);r.delete("tags"),a(r);return}const t=o.filter((r,y)=>y!==s),u=new URLSearchParams(e);t.length>0?u.set("tags",JSON.stringify(t)):u.delete("tags"),a(u)},[e,a]),m=n.useMemo(()=>{const s=h(e.get("tags"),[]);return s.length>0?s:[{name:"",key:"",value:""}]},[e]),g=n.useCallback((s,o)=>{const u=h(e.get("keywords"),[{value:""}]).map((k,P)=>P!==s?k:{...k,value:o}),r=new URLSearchParams(e);u.length===1&&!u[0].value?r.delete("keywords"):r.set("keywords",JSON.stringify(u)),a(r)},[e,a]),p=n.useCallback(()=>{const o=[...h(e.get("keywords"),[]),{value:""}],t=new URLSearchParams(e);t.set("keywords",JSON.stringify(o)),a(t)},[e,a]),w=n.useCallback(s=>{const o=h(e.get("keywords"),[]);if(o.length===1){const r=new URLSearchParams(e);r.delete("keywords"),a(r);return}const t=o.filter((r,y)=>y!==s),u=new URLSearchParams(e);t.length>0?u.set("keywords",JSON.stringify(t)):u.delete("keywords"),a(u)},[e,a]),f=n.useMemo(()=>{const s=h(e.get("keywords"),[]);return s.length>0?s:[{value:""}]},[e]);return n.useMemo(()=>({searchText:e.get("search")??"",updateSearch:c,urlTags:m,updateTag:i,addTag:l,removeTag:d,urlKeywords:f,updateKeyword:g,addKeyword:p,removeKeyword:w}),[e,c,m,i,l,d,f,g,p,w])},R=()=>{const{searchText:e,urlTags:a,urlKeywords:c}=F(),i=K(e,500).trim(),l=K(a,500),d=K(c,500),m=n.useMemo(()=>l.filter(s=>s.name&&s.key&&s.value).map(s=>({name:s.name,key:s.key,value:s.value.trim()})),[l]),g=n.useMemo(()=>d.filter(s=>s.value).map(s=>({value:s.value.trim()})),[d]),p=m.length>0,w=g.length>0;return{searchTerm:i,processedTags:m,processedKeywords:g,hasValidTags:p,hasValidKeywords:w,hasSearchCriteria:!!i||p||w}},I=(e,a="ALL")=>{const{searchTerm:c,processedTags:i,processedKeywords:l,hasSearchCriteria:d}=R(),{data:m={},isFetching:g}=L({pId:e,searchTerm:c,docType:a,params:{offset:0,limit:E,tags:i,keywords:l}},{skip:!e||!d}),{data:p={},isFetching:w}=U({searchTerm:c,docType:a,params:{offset:0,limit:E,tags:i,keywords:l}},{skip:!!e||!d});return{data:e?m:p,isFetching:g||w}},Q=(e,a)=>{const{searchTerm:c,processedTags:i,processedKeywords:l,hasSearchCriteria:d}=R(),{dataProp:m,totalProp:g}=O(e),p=n.useMemo(()=>({pId:a,searchTerm:c,docType:"ALL",params:{tags:i,keywords:l}}),[a,c,i,l]);return C({api:v,apiEndpointName:a?"searchProject":"searchAllProjects",apiArgs:p,dataProp:m,totalProp:g,skip:!d,limit:E})},O=b([[T("FEATURE"),S({dataProp:"features",totalProp:"featuresTotal"})],[T("FEATUREGROUP"),S({dataProp:"featuregroups",totalProp:"featuregroupsTotal"})],[T("FEATUREVIEW"),S({dataProp:"featureViews",totalProp:"featureViewsTotal"})],[T("TRAININGDATASET"),S({dataProp:"trainingdatasets",totalProp:"trainingdatasetsTotal"})]]);export{F as a,R as b,Q as c,I as u};
