import{t as e}from"./editable-business-trip-CtyigzMk.js";import{i as t,n,r,t as i}from"./accordion-hb1BiBOM.js";import{Co as a,Eu as o,Ln as s,Nl as c,Pd as l,So as u,Zn as d,ed as f,fn as p,pr as m,tn as h,tr as g,ut as _,xo as v,zd as y}from"./index-Q5R6-AeA.js";import{t as b}from"./page-layout-Cl29SycZ.js";var x=y(l(),1),S=o(),C=({data:i,isOpened:a,shouldValidate:o})=>{let s=d(v,i),[{data:l,fetching:f}]=c({pause:!o,query:u,variables:{id:s.id}}),p=(0,x.useMemo)(()=>o?l?.businessTrip&&(l.businessTrip.uncategorizedTransactions?.length||l?.businessTrip.summary?.errors?.length):!1,[l]),h=p||s?.accountantApproval!==`APPROVED`;return(0,S.jsxs)(r,{value:s.id,children:[(0,S.jsx)(t,{children:(0,S.jsx)(m,{inline:!0,size:12,processing:f,disabled:!h,color:p?`red`:`yellow`,zIndex:`auto`,children:s.name})}),(0,S.jsx)(n,{children:a&&(0,S.jsx)(e,{tripId:s.id,isExtended:!0},s.id)})]})},w=()=>{let{setFiltersContext:e}=(0,x.useContext)(g),[t,n]=(0,x.useState)([]),[r,o]=(0,x.useState)(!1),[{data:l,fetching:u}]=c({query:a});(0,x.useEffect)(()=>{if(!l?.allBusinessTrips?.length){n([]);return}n(l.allBusinessTrips.sort((e,t)=>e.dates?.start&&t.dates?.start?e.dates.start<t.dates.start?1:-1:e.dates?.start?-1:t.dates?.start?1:e.name.toLocaleLowerCase()<t.name.toLocaleLowerCase()?-1:1))},[l?.allBusinessTrips]);let[d,m]=(0,x.useState)([]);return(0,x.useEffect)(()=>{e((0,S.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,S.jsx)(_,{}),(0,S.jsx)(h,{content:`Toggle business trips validation`,children:(0,S.jsxs)(`div`,{className:`flex flex-row items-center gap-x-2`,children:[(0,S.jsx)(p,{checked:r??!1,onCheckedChange:e=>o(e)}),(0,S.jsx)(`span`,{className:`text-sm text-gray-500`,children:`Validate`})]})}),(0,S.jsx)(s,{filename:`business_trips`})]}))},[l,u,e,r]),(0,S.jsx)(b,{title:`Business Trips`,description:`Manage business trips`,children:t.length===0&&u?(0,S.jsx)(f,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,S.jsx)(i,{className:`w-full`,type:`multiple`,value:d,onValueChange:m,children:t?.map(e=>(0,S.jsx)(C,{data:t.find(t=>t.id===e.id),shouldValidate:r,isOpened:d.includes(e.id)},e.id))})})};export{w as BusinessTrips};