import{n as x,j as r,aA as b,aB as C,B as y,aC as E,aE as M,r as d,az as w,u as S,f as v}from"./index-Db-xuq0b.js";import{A as z}from"./AdvancedTable-CC9ioMU-.js";import{C as I,a as K,b as B,d as T}from"./card-BBWyxDss.js";import{a as A}from"./userService-BHeFzZdn.js";import{E as U}from"./ellipsis-CbtaBcvT.js";import{E as L}from"./eye-Bhud4znU.js";import{f as P}from"./organizationService-DPKKJMFw.js";import{S as k}from"./FormFields-BA7SVWfi.js";import"./table-D3n3VABd.js";import"./select-BoQxM42A.js";import"./chevron-left-DCpEaNzo.js";import"./utils-BncSPdK1.js";import"./badge-D7JvaQeJ.js";import"./command-Cr0tMDDu.js";import"./search-CM5F2ZRy.js";import"./popover-X-j_SRnG.js";import"./Popover-CzANYrEa.js";import"./use-uncontrolled-C3HRHW6t.js";import"./separator-BaOOgzZX.js";import"./refresh-cw-JB7N413f.js";import"./form-BeLK5rTt.js";import"./index.esm-BG4gweZJ.js";import"./label-CsFy6wpo.js";import"./multi-select-C9K8HXhI.js";import"./single-select-D9ZG1edj.js";const q=(n,l)=>x({queryKey:["migratedData",n,l],queryFn:async()=>{const{data:m}=await A(n,l);return m}}),F=(n,l,m)=>{const g=t=>{m(`/user-management/migrated-records-management/view/${t}`)};return[{accessorKey:"record.referenceNumber",header:"Reference Number",cell:({row:t})=>{var e,a;return(a=(e=t.original)==null?void 0:e.record)==null?void 0:a.referenceNumber}},{accessorKey:"record.letterNumber",header:"Letter Number",cell:({row:t})=>{var e,a;return(a=(e=t.original)==null?void 0:e.record)==null?void 0:a.letterNumber}},{accessorKey:"record.metadata.uploadedBy.en",header:"Uploaded By",cell:({row:t})=>{var e,a,s;return n(((s=(a=(e=t.original)==null?void 0:e.record)==null?void 0:a.metadata)==null?void 0:s.uploadedBy)??{en:"-",am:"-"})}},{accessorKey:"record.metadata.organizationName.en",header:"Organization",cell:({row:t})=>{var e,a,s;return n(((s=(a=(e=t.original)==null?void 0:e.record)==null?void 0:a.metadata)==null?void 0:s.organizationName)??{en:"-",am:"-"})}},{accessorKey:"record.dispatchedDate",header:"Dispatched Date",cell:({row:t})=>{var e,a;return new Date((a=(e=t.original)==null?void 0:e.record)==null?void 0:a.dispatchedDate).toLocaleString()}},{accessorKey:"status",header:"Status",cell:({row:t})=>{var e;return(e=t.original)==null?void 0:e.status}},{accessorKey:"record.content",header:"Subject",cell:({row:t})=>{var e,a,s;return((s=(a=(e=t.original)==null?void 0:e.record)==null?void 0:a.content[0])==null?void 0:s.subject)||"-"}},{id:"actions",cell:({row:t})=>{const e=t.original.record;return r.jsxs(b,{children:[r.jsx(C,{asChild:!0,children:r.jsx(y,{variant:"ghost",size:"sm",children:r.jsx(U,{className:"h-4 w-4"})})}),r.jsx(E,{align:"end",children:r.jsxs(M,{onClick:()=>g(e.id),children:[r.jsx(L,{className:"h-4 w-4 mr-2"}),l("userRecord.View")]})})]})}}]};function V(){const[n,l]=d.useState(0),m=10,[g,t]=d.useState(!1),e=w(),{t:a}=S(),s=v(),{data:o,isLoading:O,error:H}=x({queryKey:["organizations"],queryFn:P,staleTime:300*1e3}),[u,h]=d.useState(null),j=d.useMemo(()=>(o==null?void 0:o.items?.map(i=>({id:i.id,name:i.name,hierarchyType:"organization",value:i.units.length===1?i.units[0].id:"",children:Array.isArray(i.units)&&i.units.length>0?i.units?.map(c=>({id:c.id,name:c.name,hierarchyType:"unit",value:c.id,children:[]})):[]})))||[],[o,e]);d.useEffect(()=>{if(!u){const i=o==null?void 0:o.items.flatMap(c=>c.units).find(c=>c.id);i&&h(i.id)}},[o]),d.useEffect(()=>{u&&sessionStorage.setItem("selectedUnitId",u)},[u]),d.useEffect(()=>{const i=sessionStorage.getItem("selectedUnitId");i&&h(i)},[]);const{data:p,isLoading:D}=q(u??"",{skip:n*m,take:m,orderBy:"migratedAt:DESC"}),f=i=>{l(i)},N=()=>{t(!0)};return D?r.jsx("div",{children:a("loading")}):r.jsx("div",{className:"p-6 space-y-6",children:r.jsxs(I,{className:"col-span-2 shadow-none border-none bg-transparent px-0",children:[r.jsxs(K,{className:"flex flex-row justify-between items-center px-0",children:[r.jsx(B,{className:"text-xl font-semibold ",children:a("migration.migratedData")}),r.jsx(y,{onClick:N,children:a(g?"migration.exporting":"migration.exportData")})]}),r.jsx("div",{className:"mb-4",children:r.jsx(k,{label:a("selectUnit"),options:j,value:u,onChange:h,collapsible:!0})}),r.jsx(T,{className:"px-0",children:r.jsx(z,{columns:F(e,a,s),data:(p==null?void 0:p.items)||[],tableName:"Migrated Data",toolBarPosition:"right",itemCount:(p==null?void 0:p.count)||0,pageIndex:n,onPageChange:f,nextFunction:()=>f(n+1),prevFunction:()=>f(Math.max(n-1,0))})})]})})}function he(){return r.jsx(V,{})}export{he as default};
