import{M as A,S as u,j as t,c as G}from"./vendor-mui-CBBEb17G.js";import{al as k,g3 as B,e as S,at as L,aO as U,dD as b,c4 as V,et as $,bx as z,v as F,aP as T,x as K,aX as X,c$ as W,ao as Y,aT as _}from"./index-IP_FWtso.js";import{a as i}from"./vendor-react-BBazpZul.js";import{a as p}from"./vendor-utils-BveVE6Uf.js";import{B as q}from"./index-BkhbTDKf.js";import{T as J}from"./index-Dz6vPtCj.js";import"./vendor-charts-tGnAgELZ.js";const Q=k(A)`
  box-shadow: 0 3px 20px rgb(0 0 0 / 4%);
  background-color: rgb(255, 255, 255);
  padding: 10px 20px;
  height: 100%;

  .MuiDataGrid-cell {
    cursor: pointer !important;
  }
`;k(u)`
  margin-bottom: 0;

  .btc-icons {
    background: rgba(51, 83, 178, 0.04);
    min-width: 49px;
    margin: 0 5px;
  }
`;const E=()=>({addAdministrativeCostAsync:async e=>(e.title=B(e.title),(await p.post("AdministrativeCost/AddAdministrativeCost",e)).data),getAdministrativeCostsAsync:async(e,s,l)=>(await p.get("AdministrativeCost/GetAdministrativeCosts",{params:{clinicId:e,officeId:s,name:l}})).data,getAccountingPersonByIdAsync:async e=>(await p.get(`AdministrativeCost/GetAdministrativeCostById/${e}`)).data,updateAdministrativeCostAsync:async e=>(e.title=B(e.title),(await p.put(`AdministrativeCost/UpdateAdministrativeCost/${e.id}`,e)).data),deleteAccountingAsync:async e=>{await p.delete(`AdministrativeCost/DeleteAdministrativeCost/${e}`)}}),P=i.createContext(void 0),Z=({children:a})=>{const{clinicId:o,officeId:c}=S(d=>d.doctorData),{getAdministrativeCostsAsync:r}=E(),[n,e]=i.useState(!1),[s,l]=i.useState([]),[g,f]=i.useState(null),m=async d=>{e(!0);const{data:j}=await r(o,c,d||null);l(j),e(!1)},h=d=>{m(d)};i.useEffect(()=>{m()},[]);const C={loading:n,getData:m,search:h,List:s,rowSelected:g,setRowSelected:f};return t.jsx(P.Provider,{value:C,children:a})},w=()=>i.useContext(P),tt=()=>{const{clinicId:a,officeId:o}=S(v=>v.doctorData),{addAdministrativeCostAsync:c,deleteAccountingAsync:r,updateAdministrativeCostAsync:n}=E(),{getData:e,rowSelected:s,setRowSelected:l}=w(),g=L(),{register:f,handleSubmit:m,formState:{errors:h},reset:C,setValue:d}=U(),[j,x]=i.useState(!1),[y,I]=i.useState(!1),R=()=>{I(!1),x(!0),C()},O=()=>{I(!0),x(!0),d("title",s==null?void 0:s.title)},H=()=>{s&&g({content:"آیا از حذف این آیتم مطمئن هستید؟"}).then(async()=>{await r(s.id),e(),l(null)}).catch(()=>{})},M=async v=>{const{title:N}=v,D={clinicId:a,officeId:o,title:String(N)};y?(await n({id:s==null?void 0:s.id,...D}),l(null)):await c(D),e(),x(!1)};return t.jsxs(t.Fragment,{children:[t.jsxs(u,{direction:"row",paddingY:1,spacing:1,children:[t.jsx(b,{onClick:R,children:t.jsx(V,{fontSize:"large",color:"success"})}),t.jsx(b,{onClick:()=>s&&O(),children:t.jsx($,{fontSize:"large",color:s?"primary":"disabled"})}),t.jsx(b,{onClick:H,children:t.jsx(z,{fontSize:"large",color:s?"error":"disabled"})})]}),j&&t.jsxs(F,{title:y?"ویرایش هزینه":"افزودن هزینه",maxWidth:"xs",onClose:()=>x(!1),children:[t.jsx(G,{children:t.jsx(u,{component:"form",paddingX:4,marginBottom:0,paddingTop:1.5,spacing:1.4,alignItems:"center",children:t.jsx(u,{width:"100%",children:t.jsx(T,{label:"عنوان هزینه",name:"title",register:f,validation:{required:!0},error:!!h.title})})})}),t.jsx(K,{onClose:()=>x(!1),onSubmit:m(M),submitlabel:y?"ویرایش":"افزودن"})]})]})},et=[{title:"نام",dataIndex:"title",key:"title",width:120}],st=()=>{const{List:a,loading:o,setRowSelected:c}=w(),r=n=>{c(n)};return t.jsx(X,{loading:o,rowKey:"id",columns:et||[],data:a||[],onClick:n=>r(n),boxProps:{height:"75vh"}})},nt=()=>{const{userType:a}=S(e=>e.user),{search:o}=w(),[c,r]=i.useState(""),n=()=>{o(c)};return t.jsxs(u,{className:"h-full overflow-y-auto p-2 pb-10 border-l",spacing:1,children:[t.jsx(J,{className:+a===W.accountant?"!bg-[#b0d8e7]":"",children:"نام"}),t.jsx(T,{onChange:r}),t.jsx(u,{component:"form",gap:1,children:t.jsx(Y,{fullWidth:!0,startIcon:t.jsx(_,{}),onClick:n,children:"جستجو"})})]})},it=()=>t.jsxs(Q,{className:"!px-4 !py-2",children:[t.jsx(q,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"تعریف هزینه های اداری"}),t.jsxs(A,{container:!0,xs:12,spacing:1,className:"!h-full",children:[t.jsx(A,{item:!0,xs:12,sm:2,children:t.jsx(nt,{})}),t.jsxs(A,{item:!0,xs:12,sm:10,spacing:1,children:[t.jsx(tt,{}),t.jsx(st,{})]})]})]}),mt=()=>t.jsx(Z,{children:t.jsx(it,{})});export{mt as default};
