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