import{n as P,aX as T,r,j as e,q as B,A as D,ar as F,o as n,G as o,t as i,T as m,B as S}from"./vendor-BuNhBR-q.js";import{P as I,g as L,U as N,e as E}from"./index-DzxWaMzc.js";import{B as M,P as O}from"./ParentCard-DFHA8fzx.js";import{L as R}from"./LogoLoader-B_2Vvdpp.js";const f="60%",H=()=>{const j=P(),{id:l}=T(),[_,y]=r.useState(!1),[s,b]=r.useState({section:"",form_no:"",nature_of_compliance:"",remarks:"",is_active:!0}),[C,c]=r.useState(!1),[v,h]=r.useState(""),[k,p]=r.useState("success"),W=r.useMemo(()=>{try{return JSON.parse(sessionStorage.getItem("userProfile")||"{}")}catch{return{}}},[]),z=String(W.id??""),u=(t,d)=>{b(x=>({...x,[t]:d}))},w=async()=>{var t,d,x;if(!s.section||!s.nature_of_compliance){h("Please fill all required fields"),p("error"),c(!0);return}y(!0);try{const a=L(N.createStatutorySection,z),A={statutory_id:Number(l),section:s.section,form:s.form_no||null,nature_of_compliance:s.nature_of_compliance,remarks:s.remarks||null},g=await E.post(a,A);(t=g==null?void 0:g.data)!=null&&t.success&&(h("Statutory section added successfully"),p("success"),c(!0),setTimeout(()=>j(`/statutory/${l}`),1200))}catch(a){h(((x=(d=a==null?void 0:a.response)==null?void 0:d.data)==null?void 0:x.message)||(a==null?void 0:a.message)||"Failed to add section"),p("error"),c(!0)}finally{y(!1)}};return _?e.jsx(R,{}):e.jsxs(I,{title:"Add Statutory Section",children:[e.jsx(B,{open:C,autoHideDuration:3e3,onClose:()=>c(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(D,{severity:k,variant:"filled",children:v})}),e.jsx(M,{title:"Add Section",items:[{to:"/",title:"Dashboard"},{to:"/statutory",title:"Statutory Master"},{to:`/statutory/${l}`,title:"Statutory Details"},{title:"Add Section"}]}),e.jsx(O,{title:"",children:e.jsxs(F,{sx:{p:3,boxShadow:"none"},children:[e.jsx(n,{fontSize:18,fontWeight:600,mb:3,align:"center",children:"Statutory Section Add"}),e.jsxs(o,{container:!0,spacing:3,alignItems:"center",children:[e.jsx(o,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsxs(i,{sx:{width:f},children:[e.jsxs(n,{fontSize:15,fontWeight:500,mb:.5,children:["Section / Rule ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsx(m,{fullWidth:!0,size:"small",value:s.section,onChange:t=>u("section",t.target.value)})]})}),e.jsx(o,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsxs(i,{sx:{width:f},children:[e.jsxs(n,{fontSize:15,fontWeight:500,mb:.5,children:["Form Name ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsx(m,{fullWidth:!0,size:"small",value:s.form_no,onChange:t=>u("form_no",t.target.value)})]})}),e.jsx(o,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsxs(i,{sx:{width:f},children:[e.jsxs(n,{fontSize:15,fontWeight:500,mb:.5,children:["Nature of Compliance ",e.jsx("span",{style:{color:"red"},children:"*"})]}),e.jsx(m,{fullWidth:!0,size:"small",multiline:!0,rows:2,value:s.nature_of_compliance,onChange:t=>u("nature_of_compliance",t.target.value)})]})}),e.jsx(o,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsxs(i,{sx:{width:f},children:[e.jsx(n,{fontSize:15,fontWeight:500,mb:.5,children:"Remarks"}),e.jsx(m,{fullWidth:!0,size:"small",multiline:!0,rows:2,value:s.remarks,onChange:t=>u("remarks",t.target.value)})]})})]}),e.jsxs(i,{sx:{display:"flex",justifyContent:"center",gap:2,mt:4},children:[e.jsx(S,{variant:"contained",sx:{minWidth:135,px:2,fontWeight:501},onClick:w,children:"Save"}),e.jsx(S,{type:"button",color:"error",sx:{minWidth:135,px:2,fontWeight:501},onClick:()=>j(`/statutory/${l}`),children:"Cancel"})]})]})})]})};export{H as default};
