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