import{j as t,c as P,S as p,W as N,B as I}from"./vendor-mui-CBBEb17G.js";import{B as z}from"./index-BkhbTDKf.js";import{a as c}from"./vendor-react-BBazpZul.js";import{aO as B,v as M,by as v,aP as E,x as R,at as T,aQ as F,aX as O,h6 as W,I as f,z as j,J as y}from"./index-IP_FWtso.js";import{S as K}from"./index-D7-0uPSw.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const L=({onClose:o,onSubmit:x,selectedItem:l,loading:i})=>{const{handleSubmit:h,control:r,formState:{errors:s}}=B({defaultValues:{title:(l==null?void 0:l.title)??""}}),g=a=>{x({title:a.title})};return t.jsxs(M,{title:l?"ویرایش نحوه آشنایی":"افزودن نحوه آشنایی جدید",maxWidth:"xs",onClose:o,children:[t.jsx(P,{className:"m-1 !p-2",children:t.jsx(p,{component:"form",children:t.jsx(v,{name:"title",control:r,defaultValue:"",rules:{required:!0},render:({field:{onChange:a,value:m}})=>t.jsx(E,{label:"عنوان",fullWidth:!0,error:!!s.title,className:"!mt-1",value:m,onChange:a})})})}),t.jsx(R,{onClose:o,onSubmit:h(g),loading:i})]})},Q=()=>{const o=new W,x=T(),[l,i]=c.useState(!1),[h,r]=c.useState(!1),[s,g]=c.useState(null),[a,m]=c.useState(null),[S,b]=c.useState({PageNumber:1,PageSize:50}),d=async()=>{try{i(!0),m(null);const{data:e}=await o.getAsync(S);g(e)}finally{i(!1)}},w=async e=>{try{i(!0);const{data:n}=await o.toggleAsync(e);y.success("تغییر وضعیت با موفقیت انجام شد"),d()}finally{i(!1)}},C=async e=>{try{i(!0);let n=null;if(a){const{message:u}=await o.updateAsync({id:a.id,title:e.title});n=u}else{const{message:u}=await o.addAsync({title:e.title});n=u}n&&y.success(n),r(!1),d()}finally{i(!1)}},k=async()=>{try{if(i(!0),!a)return;x({content:"آیا از حذف این مورد اطمینان دارید؟"}).then(async()=>{const{message:e}=await o.deleteAsync(a.id);y.success(e),d()}).catch(()=>{})}finally{i(!1)}};c.useEffect(()=>{d()},[]);const A=[{title:"ردیف",key:"num",width:70,render:(e,n,u)=>j(u+1)},{title:"شناسه",key:"id",dataIndex:"id",width:70,render:e=>j(e)},{title:"عنوان",key:"title",dataIndex:"title",width:200},{title:"وضعیت",key:"isDelete",dataIndex:"isDelete",width:70,render:(e,n)=>t.jsx(I,{variant:"contained",size:"small",color:e?"error":"success",onClick:()=>w(n.id),children:e?"غیر فعال":"فعال"})}],D=[{id:1,title:"جدید",icons:t.jsx(f.AddIcon,{color:"success"}),disabled:!1,onClick:()=>r(!0)},{id:2,title:"ویرایش",icons:t.jsx(f.EditIcon,{color:"primary"}),disabled:!a,onClick:()=>r(!0)},{id:3,title:"حذف",icons:t.jsx(f.DeleteIcon,{color:"error"}),disabled:!a,onClick:()=>k()},{id:4,title:"بازیابی",icons:t.jsx(f.RefreshIcon,{color:"info"}),disabled:!1,onClick:()=>d()}];return t.jsxs(p,{spacing:1,p:1,children:[t.jsx(p,{direction:"row",alignItems:"center",spacing:1,children:D.map(e=>t.jsx(N,{title:e.title,children:t.jsx(F,{onClick:e.onClick,disabled:e.disabled,children:e.icons})},e.id))}),t.jsx(p,{className:"h-[70vh]",children:t.jsx(O,{columns:A,data:(s==null?void 0:s.list)??[],rowKey:"id",loading:l,onClick:e=>m(e),totalCount:(s==null?void 0:s.pagination.totalCount)??0,pageNumber:((s==null?void 0:s.pagination.pageNumber)??1)-1,pageSize:(s==null?void 0:s.pagination.pageSize)??50,onPaginationLoad:(e,n)=>b({PageNumber:e+1,PageSize:n})})}),h&&t.jsx(L,{selectedItem:a,onSubmit:C,loading:l,onClose:()=>r(!1)})]})},H=()=>t.jsxs(K,{className:"!px-4 !py-2 !space-y-2",children:[t.jsx(z,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"نحوه آشنایی"}),t.jsx(Q,{})]});export{H as default};
