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