import{Au as e,Dd as t,Eu as n,It as r,Ni as i,Nl as a,Pd as o,Yl as s,dt as c,ed as l,nt as u,tr as d,va as f,w as p,zd as m}from"./index-Q5R6-AeA.js";import{t as h}from"./use-url-query-Cos8nKH-.js";import{t as g}from"./page-layout-Cl29SycZ.js";import{t as _}from"./business-header-CxIiwrXa.js";var v=m(o(),1),y=n();function b({activePage:e,setPage:t,totalPages:n=1,businessName:r,setBusinessName:a}){let{get:o,set:s}=h(),[c,l]=(0,v.useState)(r);(0,v.useEffect)(()=>{let t=e>0?e.toFixed(0):void 0;t!==o(`page`)&&t!==`0`&&s(`page`,t)},[e,o,s]),(0,v.useEffect)(()=>{let e=setTimeout(()=>{a(c)},600);return()=>{clearTimeout(e)}},[c,a]);let u=e=>{l(e)};return(0,y.jsxs)(`div`,{className:`flex flex-row gap-5 items-center`,children:[(0,y.jsx)(p,{className:`flex-fit w-fit mx-0`,currentPageIndex:e,onChange:t,totalPages:n}),(0,y.jsx)(i,{className:`w-72`,placeholder:`Business Name`,defaultValue:r??void 0,onChange:e=>u(e.target.value===``?void 0:e.target.value)})]})}var x=()=>{let{get:n}=h(),[i,o]=(0,v.useState)(n(`page`)?Number(n(`page`)):0),[p,m]=(0,v.useState)(n(`name`)?n(`name`):void 0),{setFiltersContext:x}=(0,v.useContext)(d),[{data:S,fetching:C},w]=a({query:f,variables:{page:i,limit:100,name:p}}),T=t(),[E,D]=(0,v.useState)([]),O=(0,v.useCallback)((e,t)=>{E.map(e=>e.id).includes(e)?D(E.filter(t=>t.id!==e)):D([...E,{id:e,onChange:t}])},[E]);function k(){D([])}(0,v.useEffect)(()=>{x((0,y.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,y.jsx)(b,{activePage:i,setPage:o,businessName:p,setBusinessName:m,totalPages:S?.allBusinesses?.pageInfo.totalPages}),(0,y.jsx)(r,{selected:E,resetMerge:k})]}))},[S,i,p,x,o,m,E]);let A=S?.allBusinesses?.nodes.filter(e=>e.__typename===`LtdFinancialEntity`).sort((e,t)=>e.name.toLowerCase()>t.name.toLowerCase()?1:-1)??[],j=new Set(E.map(e=>e.id));return(0,y.jsx)(g,{title:`Businesses (${S?.allBusinesses?.pageInfo.totalRecords??``})`,description:`All businesses`,headerActions:(0,y.jsx)(`div`,{className:`flex items-center py-4 gap-4`,children:(0,y.jsx)(c,{description:``,onAdd:()=>w()})}),children:C?(0,y.jsx)(`div`,{className:`flex flex-row justify-center`,children:(0,y.jsx)(l,{className:s(`h-10 w-10 animate-spin mr-2`)})}):(0,y.jsx)(`div`,{className:`space-y-2`,children:A.map(t=>(0,y.jsx)(`div`,{className:`group relative border rounded-lg hover:shadow-md transition-shadow`,children:(0,y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`pl-4 flex items-center`,children:(0,y.jsx)(u,{checked:j.has(t.id),onCheckedChange:()=>{O(t.id,()=>{})},className:`h-4 w-4 rounded border-gray-300 cursor-pointer`,onClick:e=>e.stopPropagation()})}),(0,y.jsx)(`div`,{role:`button`,tabIndex:0,className:`flex-1 cursor-pointer`,onClick:()=>{T(e.BUSINESSES.DETAIL(t.id),{state:{from:e.BUSINESSES.ALL}})},onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),T(e.BUSINESSES.DETAIL(t.id),{state:{from:e.BUSINESSES.ALL}}))},children:(0,y.jsx)(_,{data:t})})]})},t.id))})})};export{x as Businesses};