import{j as s,b as E,ak as g,I as A,T as x}from"./mui-vendor-CkIVaoQP.js";import{r as _}from"./react-vendor-CmFgShSM.js";import{L as o,j as i,h as a,A as f,u as T,G as h,c as I,b as D}from"./index-Cr86_nOs.js";import{d as G}from"./Check-CtJeUoc2.js";import{d as N}from"./Edit-DVocKJob.js";import{a as c,u as S}from"./redux-vendor-B7uoacJt.js";const R=c("PROVINCE_MANAGE_TRADES_EDIT_PERCENTS",async(r,{dispatch:t})=>{try{t(o());const{data:e,status:n}=await i.put("market-kill-houses/0/",r);return t(a()),{data:e,status:n}}catch(e){return t(a()),{error:e.response.data.result}}}),j=c("PROVINCE_MANAGE_GUILD_TRADES_EDIT_PERCENTS",async(r,{dispatch:t})=>{try{t(o());const{data:e,status:n}=await i.put("guilds-for-configs/0/",r);return t(a()),{data:e,status:n}}catch(e){return t(a()),{error:e.response.data.result}}}),b=c("PROVINCE_MANAGE_GUILD_TRADES_EDIT_ALL_PERCENTS",async(r,{dispatch:t})=>{try{t(o());const{data:e,status:n}=await i.put("guilds-configs/0/",r);return t(a()),{data:e,status:n}}catch(e){return t(a()),{error:e.response.data.result}}}),B=c("PROVINCE_MANAGE_GUILD_TRADES_GET_PERCENTS",async(r,{dispatch:t})=>{try{t(o());const{data:e,status:n}=await i.get("guilds-configs",{params:r});return t(a()),{data:e,status:n}}catch(e){return t(a()),{error:e.response.data}}}),v=I({commitmentPercent:D().min(0,"درصد نمی‌تواند کمتر از ۰ باشد").max(100,"درصد نمی‌تواند بیشتر از ۱۰۰ باشد").required("درصد تعهد الزامی است").integer("درصد باید عدد صحیح باشد")}),U=({amount:r,updateTable:t,item:e,isGuild:n,isDashboard:l})=>{const[F,d]=_.useState(!1),[p]=_.useContext(f),P=S(),u=T({initialValues:{commitmentPercent:r||0},validationSchema:v,onSubmit:m=>{P((l?b:n?j:R)({...l?{}:{key:e==null?void 0:e.key},out_province_free_buying_commitment_percent:m==null?void 0:m.commitmentPercent})).then(C=>{C.payload.error?p({vertical:"top",horizontal:"center",msg:C.payload.error,severity:"error"}):(t(),p({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}),t(),d(!1)}}),y=()=>{u.setValues({commitmentPercent:r||0}),u.setErrors({}),d(!0)};return s.jsx(h,{xs:12,container:!0,justifyContent:"center",alignItems:"center",children:F?s.jsxs(E,{component:"form",onSubmit:u.handleSubmit,display:"flex",alignItems:"center",gap:1,children:[s.jsx(g,{size:"small",id:"commitmentPercent",name:"commitmentPercent",label:"درصد تعهد",variant:"outlined",type:"number",value:u.values.commitmentPercent,style:{width:80},inputProps:{min:0,max:100,step:1},onChange:u.handleChange,onBlur:u.handleBlur,error:u.touched.commitmentPercent&&!!u.errors.commitmentPercent,helperText:u.touched.commitmentPercent&&u.errors.commitmentPercent}),s.jsx(A,{size:"small",color:"primary",type:"submit",disabled:!u.isValid||u.isSubmitting,children:s.jsx(G,{})})]}):s.jsxs(E,{display:"flex",alignItems:"center",children:[s.jsxs(x,{variant:"caption",children:["%",r||0]}),s.jsx(A,{size:"small",color:"primary",onClick:y,children:s.jsx(N,{})})]})})};export{U as P,j as a,B as b,R as c,b as p};
