import{ag as p,aT as w,w as E,J as I}from"./app-BgLa5dit.js";const T="recentlyViewed",x=1*365*24*3600,y=12;function R(t){switch(t){case p.Organisation:return"organisations";case p.Customer:return"customers";case p.User:return"users"}}function g(t){const n=new Set;return(t??[]).map(e=>typeof e=="string"?{id:e}:e).filter(e=>{const s=e==null?void 0:e.id;return typeof s!="string"||!/^\d+$/.test(s)||n.has(s)?!1:(n.add(s),!0)})}function f(){const t=I.cacheGet(T);return t?{customers:g(t.customers),organisations:g(t.organisations),users:g(t.users)}:{customers:[],organisations:[],users:[]}}function l(t){I.cacheSet(T,t,x)}function S(t){return[...t.filter(n=>n.pinned),...t.filter(n=>!n.pinned)]}function _(t,n){const e=f(),s=R(n),d=e[s]??[],i=t.toString(),a=d.find(u=>u.id===i)??{id:i},r=d.filter(u=>u.id!==i);let o;if(r.length<y)o=[a,...r];else{const u=E.findLastIndex(r,m=>!m.pinned);o=u===-1?r:[a,...r.filter((m,h)=>h!==u)]}l({...e,[s]:S(o)})}function C(t){const[n,e]=w.useState(()=>f()[t]??[]);function s(){const i=f(),c=n.filter(a=>a.pinned);l({...i,[t]:c}),e(c)}function d(i){const c=f(),a=c[t].map(o=>o.id===i?{...o,pinned:!o.pinned}:o),r=S(a);l({...c,[t]:r}),e(r)}return{items:n,handleReset:s,handleTogglePin:d}}export{y as R,_ as a,R as g,C as u};
//# sourceMappingURL=DR2FaZH9.chunk.js.map
