import{j as e,a3 as f,d as x,I as v,ab as _,br as E,ad as k,ak as b,a4 as B,B as h,T as I,p as t}from"./mui-vendor-CkIVaoQP.js";import{b as R,r as n}from"./react-vendor-CmFgShSM.js";import{d as D}from"./Pageview-DPJOtuEI.js";import{d as S}from"./Edit-DE-0ja3Q.js";import{d as z}from"./AddCircleOutline-CRCPZlAA.js";import{a as P,u as w}from"./redux-vendor-B7uoacJt.js";import{L as N,j as G,h as y,A as L,u as O,c as $,M}from"./index-BHF9XhlR.js";const V=P("EDIT_BAR_CLEARANCE_BAR",async(s,{dispatch:r})=>{r(N());try{const{data:a,status:l}=await G.put("kill_house_free_bar/0/",s);return r(y()),{data:a,status:l}}catch(a){return r(y()),{error:a.response.data.result}}}),q=({clearanceCode:s,onSave:r,bar_key:a,register_type:l})=>{const A=w(),{openNotif:c}=R.useContext(L),[C,o]=n.useState(!1),[j,p]=n.useState(!1),F=n.useRef(null),u=O({initialValues:{clearanceCode:s||""},validationSchema:$({clearanceCode:M().required("این فیلد اجباری است!").matches(/^[A-Z0-9]+$/,"فقط حروف بزرگ و عدد مجاز است!")}),onSubmit:async m=>{p(!0);try{const i=await A(V({key:a,bar_clearance_code:m.clearanceCode}));i.error?c({vertical:"top",horizontal:"center",msg:i.error.message||"خطا در ذخیره سازی",severity:"error"}):(c({vertical:"top",horizontal:"center",msg:"کد با موفقیت ذخیره شد",severity:"success"}),r&&r(m.clearanceCode),o(!1))}catch{c({vertical:"top",horizontal:"center",msg:"خطا در ارتباط با سرور",severity:"error"})}finally{p(!1)}}}),T=()=>{o(!0)},d=l==="manual";return e.jsxs(f,{container:!0,alignItems:"center",justifyContent:"center",gap:.5,style:{width:d?"160px":"auto"},children:[u.values.clearanceCode?e.jsx(g,{clearanceCode:u.values.clearanceCode}):null,d&&e.jsx(x,{title:u.values.clearanceCode?"ویرایش کد گواهی":"ثبت کد گواهی",placement:"top",children:e.jsx(v,{size:"small",color:"primary",onClick:T,children:u.values.clearanceCode?e.jsx(S,{fontSize:"small"}):e.jsx(z,{fontSize:"small"})})}),C&&e.jsxs(_,{open:C,onClose:()=>{u.resetForm(),o(!1)},children:[e.jsx(E,{children:"ویرایش کد گواهی"}),e.jsx(k,{children:e.jsx(b,{inputRef:F,name:"clearanceCode",value:u.values.clearanceCode,onChange:u.handleChange,onBlur:u.handleBlur,error:u.touched.clearanceCode&&!!u.errors.clearanceCode,helperText:u.touched.clearanceCode&&u.errors.clearanceCode,size:"small",fullWidth:!0,autoFocus:!0})}),e.jsxs(B,{children:[e.jsx(h,{onClick:()=>{u.resetForm(),o(!1)},color:"primary",children:"لغو"}),e.jsx(h,{onClick:()=>{u.handleSubmit(),o(!1)},color:"primary",disabled:j||!u.dirty,children:"ذخیره"})]})]})]})},g=({clearanceCode:s})=>{const r=n.useRef(null),a=()=>{r.current&&r.current.submit()};return e.jsxs(f,{container:!0,style:{width:"auto"},alignItems:"center",justifyContent:"center",gap:.5,children:[e.jsx(x,{title:"مشاهده گواهینامه",arrow:!0,children:e.jsxs("form",{action:"https://e.ivo.ir/Rahgiri/Gidprnt.aspx",method:"post",target:"_blank",ref:r,style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx("input",{name:"gid",type:"hidden",value:s}),e.jsx(D,{color:"primary",onClick:a})]})}),e.jsx(I,{variant:"caption",color:"primary",children:s})]})};q.propTypes={clearanceCode:t.PropTypes.any,onSave:t.PropTypes.func,bar_key:t.PropTypes.oneOfType([t.PropTypes.string,t.PropTypes.number]),register_type:t.PropTypes.string};g.propTypes={clearanceCode:t.PropTypes.any};export{q as C};