import{j as n,c as W,S as u,p as E,Y as H,Z as P,$ as B,U as y,V as i}from"./vendor-mui-CBBEb17G.js";import{a as h}from"./vendor-react-BBazpZul.js";import{e as K,u as M,g as S,v as $,aP as q,dP as z,I as x,ao as v,b3 as g,bI as j,J as F}from"./index-DdWwwZXu.js";import"./vendor-utils-BveVE6Uf.js";import{u as J,D as O,a as Q}from"./index-DSw4vraS.js";import{C as V,a as Y}from"./column-lfAN7RYq.js";import"./vendor-charts-tGnAgELZ.js";import"./index-DQbmBtLN.js";import"./columnTypeItems-BiaRlfri.js";const re=({onClose:m})=>{var C,w;const I=new O,{insurancesSelectList:D,supplementaryInsurancesSelectList:N}=K(e=>e.data),b=M(),{states:{reportType:c}}=J(),[p,d]=h.useState(!1),[t,o]=h.useState(null),A=async()=>{try{if(d(!0),!t)return;if(!t.title){F.warning("عنوان گزارش را وارد نمایید");return}I.addAsync({...t,reportType:c,columns:t.columns.map(({uuId:e,...s})=>({...s,children:s.children.map(({uuId:a,...r})=>r)}))}),m()}finally{d(!1)}},k=async()=>{try{if(d(!0),!c)return;const{data:e}=await I.getAsync(c);if(!e)return;const s={...e,columns:e.columns.map((a,r)=>{var l;return{...a,uuId:g(),children:(l=a.children)==null?void 0:l.map((f,Z)=>({...f,uuId:g(),children:[]}))}})};o(s)}finally{d(!1)}},T=()=>{o(e=>({...e,columns:[...e.columns,{uuId:g(),width:100,columnType:Q.Text,children:[]}]}))},L=e=>{const s=t==null?void 0:t.columns.findIndex(a=>a.uuId===e);s===void 0||s===-1||o(a=>({...a,columns:a.columns.filter(r=>r.uuId!==e)}))},R=e=>{const s=t==null?void 0:t.columns.findIndex(l=>l.children.some(f=>f.uuId===e.uuId));if(s===void 0||s===-1)return;const a=t==null?void 0:t.columns[s],r=a.children.findIndex(l=>l.uuId===e.uuId);r===void 0||r===-1||o(l=>({...l,columns:[...j.toUpdate(l.columns,s,{...a,children:[...j.toUpdate(a.children,r,e)]})]}))},U=e=>{const s=t==null?void 0:t.columns.findIndex(a=>a.uuId===e.uuId);s===void 0||s===-1||o(a=>({...a,columns:[...j.toUpdate(a.columns,s,e)]}))};return h.useEffect(()=>{c&&k()},[c]),h.useEffect(()=>{!D&&b(S().getInsurancesSelectListAction()),!N&&b(S().getSupplementaryInsurancesSelectListAction())},[]),n.jsx($,{onClose:m,title:"ساختار گزارش تفکیکی مراجعین",maxWidth:"xl",fullScreen:!0,children:n.jsx(W,{className:"m-1 !p-2",children:n.jsx(u,{p:1,spacing:1,children:t?n.jsxs(u,{spacing:1,children:[n.jsx(u,{direction:"row",justifyContent:"center",children:n.jsx(q,{label:"عنوان گزارش",value:t.title,onChange:e=>o(s=>({...s,title:e})),required:!0})}),n.jsxs(E,{className:"!relative h-[75vh]  border rounded-lg",children:[p&&n.jsx(z,{}),n.jsx(H,{className:" !absolute top-0 bottom-0 left-0 right-0 !w-full !mb-[5px] overflow-auto rounded-lg",children:n.jsx(P,{size:"small",stickyHeader:!0,children:n.jsxs(B,{children:[n.jsxs(y,{children:[n.jsx(i,{width:120,align:"center",variant:"head",className:"!px-1 !bg-blue-500 !text-white border",rowSpan:2,sx:{minWidth:120},children:"ماه"}),(C=t.columns)==null?void 0:C.map((e,s)=>{var a,r,l;return n.jsx(i,{width:e.width||`${100/((a=t.columns)==null?void 0:a.length)}%`,align:"center",variant:"head",className:"!px-1 border",colSpan:(r=e.children)==null?void 0:r.length,rowSpan:(l=e.children)!=null&&l.length?1:2,sx:{minWidth:150*(e.children.length||1),backgroundColor:e.backgroundColor??"#3b6df6",color:e.color??"#ffffff"},children:n.jsx(V,{column:e,onDelete:L,onChange:U})},e.uuId)}),n.jsx(i,{width:50,align:"center",variant:"head",rowSpan:2,className:"!px-1 !bg-blue-500 !text-white border cursor-pointer",sx:{minWidth:50},children:n.jsx(x.AddIcon,{onClick:()=>T()})}),n.jsx(i,{width:120,align:"center",variant:"head",className:"!px-1 !bg-blue-500 !text-white border",rowSpan:2,sx:{minWidth:120},children:"جمع"})]}),n.jsx(y,{className:"sticky top-[38px]",children:(w=t.columns)==null?void 0:w.flatMap(e=>e.children).map((e,s)=>n.jsx(i,{width:e.width,align:"center",variant:"head",className:"!px-1  border",sx:{backgroundColor:e.backgroundColor??"#475569",color:e.color??"#ffffff"},children:n.jsx(Y,{child:e,onChange:R})},e.uuId))})]})})})]}),n.jsxs(u,{className:" flex !flex-row justify-center gap-2 !mt-2 ",children:[n.jsx(v,{color:"primary",onClick:()=>A(),startIcon:n.jsx(x.Save,{}),disabled:p,children:"ذخیره"}),n.jsx(v,{color:"error",onClick:()=>m(),startIcon:n.jsx(x.CloseIcon,{}),children:"بستن"})]})]}):n.jsx("h2",{className:"w-full p-8 text-center text-slate-700",children:p?"در حال دریافت اطلاعات ...":" داده ای برای نمایش وجود ندارد"})})})})};export{re as default};
