import{j as e,c as C,S as x,a6 as g,a8 as S,o as w}from"./vendor-mui-CBBEb17G.js";import{a as u}from"./vendor-react-BBazpZul.js";import{aO as v,v as k,by as h,bE as b,x as A,c5 as P,dD as E,I as p,aX as N,bI as F,J as U}from"./index-IP_FWtso.js";import{a as j}from"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";class q{constructor(){this.updateAsync=async i=>{const s=await j.post("CustomerClub/ServiceDetailSetting/Update",i);return s==null?void 0:s.data},this.getAsync=async i=>{const s=await j.get("CustomerClub/ServiceDetailSetting",{params:i});return s==null?void 0:s.data}}}const L=({defaultValue:n,onClose:i,onSubmit:s,loading:l})=>{const{handleSubmit:f,control:r,reset:d}=v({defaultValues:{isDiscountable:!1,maxDiscountPercent:0,score:0}});return u.useEffect(()=>{n&&d(n)},[n]),e.jsxs(k,{onClose:i,title:`ویرایش اطلاعات خدمت ${n.serviceName}`,children:[e.jsx(C,{className:"flex-1 m-1 !p-2",children:e.jsxs(x,{spacing:2,component:"form",children:[e.jsx(h,{name:"score",control:r,rules:{required:!1},render:({field:a})=>e.jsx(b,{...a,label:"امتیاز",fullWidth:!0,minValue:0})}),e.jsx(h,{name:"isDiscountable",control:r,rules:{required:!1},render:({field:{onChange:a,value:D}})=>e.jsx(g,{label:"امکان تخفیف",control:e.jsx(S,{}),checked:D,onChange:a})}),e.jsx(h,{name:"maxDiscountPercent",control:r,rules:{required:!1},render:({field:a})=>e.jsx(b,{...a,label:"ماکزیمم درصد تخفیف",fullWidth:!0,maxValue:100,minValue:0})})]})}),e.jsx(A,{onClose:i,onSubmit:f(s),loading:l})]})},O=()=>{const n=new q,[i,s]=u.useState(!1),[l,f]=u.useState([]),[r,d]=u.useState(null),a=async t=>{var c;try{s(!0),d(null);const{data:m}=await n.getAsync({serviceDetailName:(c=t==null?void 0:t.trim())!=null&&c.length?t:void 0});m&&f(m)}finally{s(!1)}},D=async t=>{try{if(s(!0),!r)return;const c=l.findIndex(o=>o.serviceDetailId===r.serviceDetailId);if(c<0)return;const m=F.toUpdate(l,c,{...l[c],score:t.score,isDiscountable:t.isDiscountable,maxDiscountPercent:t.maxDiscountPercent}),{message:I}=await n.updateAsync({services:m.map(o=>({isDiscountable:o.isDiscountable??!1,maxDiscountPercent:o.maxDiscountPercent??0,score:o.score??0,serviceDetailId:o.serviceDetailId}))});U.success(I),a()}finally{s(!1)}};u.useEffect(()=>{a()},[]);const y=[{title:"ویرایش",key:"serviceDetailId",dataIndex:"serviceDetailId",width:40,render:(t,c)=>e.jsx(w,{color:"primary",size:"small",className:"!m-0 !p-0",onClick:()=>d(c),children:e.jsx(p.EditIcon,{})})},{title:"نام خدمت",key:"serviceName",dataIndex:"serviceName",width:200},{title:"کد ملی",key:"nationalCode",dataIndex:"nationalCode",width:100,render:t=>t||""},{title:"امتیاز",key:"score",dataIndex:"score",width:100},{title:"امکان تخفیف",key:"isDiscountable",dataIndex:"isDiscountable",width:100,render:t=>t?"دارد":"ندارد"},{title:"ماکزیمم درصد تخفیف",key:"maxDiscountPercent",dataIndex:"maxDiscountPercent",width:100,render:t=>t||""}];return e.jsxs(x,{className:"h-full p-2 px-4",spacing:1,children:[e.jsxs(x,{direction:"row",alignItems:"center",spacing:2,children:[e.jsx(P,{onChange:a,fullWidth:!0,label:"جستجوی نام خدمت"}),e.jsx(E,{onClick:()=>a(),children:e.jsx(p.RefreshIcon,{color:"info"})})]}),e.jsx(x,{className:"h-full",children:e.jsx(N,{columns:y,data:l,rowKey:"serviceDetailId",loading:i})}),r&&e.jsx(L,{onClose:()=>d(null),defaultValue:r,onSubmit:D,loading:i})]})};export{O as default};
