import{useCallback as c,useEffect as S,useState as m}from"react";import{useSearchParams as p}from"react-router-dom";function h(){const[s,a]=p(),l=s.get("sort")||null,[e,r]=m(l);S(()=>{const t=new URLSearchParams(s);e?t.set("sort",e):t.delete("sort"),a(t,{replace:!0})},[e,s,a]);const u=c((t,n)=>{const o=n==="desc"?t:`-${t}`;r(e===o?null:o)},[e,r]),i=c((t,n)=>{if(!t||!e)return!1;const o=n==="desc"?t:`-${t}`;return e===o},[e]);return{sortOption:e,setSortOption:r,handleSortClick:u,isColumnSorted:i}}export{h as useCatalogSort};
