import{H as M}from"./HeaderBreadcrumbs.da67f38c.js";import{P as Q}from"./Page.4c1db0aa.js";import{al as I,bi as R,aQ as J,a as K,r as d,j as o,S as F,f as a,P as U,as as V,av as X,ax as x,aq as T,ar as k,ay as Y,B as Z,T as $,az as y,aR as C}from"./index.8f299a7d.js";import{C as aa}from"./CorporateTabNavigations.42a351a3.js";import{B as ea}from"./BasePagination.56fc59df.js";import{C as A}from"./Card.1ec83a31.js";import{T as ta}from"./TableContainer.b8d5000e.js";import{T as ra,a as S,b as f,c as n}from"./TableRow.d2ef76cd.js";import{G as P}from"./Grid.358b274d.js";function na(){I();const{corporate_id:u}=R(),[m,_]=J();K();const[E,B]=d.exports.useState(!0),[l,v]=d.exports.useState({current_page:1,data:[],path:"",first_page_url:"",last_page:1,last_page_url:"",next_page_url:"",prev_page_url:"",per_page:10,from:0,to:0,total:0});function N(t){const e=d.exports.useRef(null),[r,h]=d.exports.useState(""),[p,D]=d.exports.useState("active"),G=s=>{var c;const i=(c=s.target.value)!=null?c:"";h(i)},H=s=>{var w;const i=(w=s.target.value)!=null?w:"";console.log("changing to",i),D(i);const c={search:r,status:i};t.onSearch(c)},W=s=>{s==null||s.preventDefault();const i={search:r,status:p};t.onSearch(i)};return d.exports.useEffect(()=>{var s,i,c;h((s=m.get("search"))!=null?s:""),D((c=(i=m.get("status"))!=null?i:p)!=null?c:"active")},[m]),a("form",{id:"search-form",onSubmit:W,style:{width:"100%"},children:o(P,{container:!0,spacing:2,children:[a(P,{item:!0,xs:9,children:a(V,{id:"search-input",ref:e,label:"Search",variant:"outlined",fullWidth:!0,onChange:G,value:r})}),a(P,{item:!0,xs:3,children:o(X,{label:"Status",value:p,onChange:H,sx:{width:"100%"},children:[a(x,{value:"active",children:"Active"}),a(x,{value:"inactive",children:"Inactive"}),a(x,{value:"all",children:"All"})]})}),a(T,{type:"submit",variant:"outlined",sx:{p:1.8,display:"none"},children:"Search"})]})})}const j=t=>{C("Fuck yuo"),y.put("/corporates/"+u+"/formulariums/"+t.id+"/activate").then(()=>{v({...l,data:l.data.map(e=>e.id===t.id?{...e,status:"active"}:e)})}).catch(e=>{var r,h,p;console.log(e),C((p=(h=(r=e.data)==null?void 0:r.message)!=null?h:e.message)!=null?p:"Failed Processing Request",{variant:"error"})})},q=t=>{y.put("/corporates/"+u+"/formulariums/"+t.id+"/deactivate").then(()=>{v({...l,data:l.data.map(e=>e.id===t.id?{...e,status:"inactive"}:e)})}).catch(e=>{var r;C((r=e.message)!=null?r:"Failed Processing Request",{variant:"error"})})};function L(t){const{row:e}=t,[r,h]=k.useState(!1);return o(k.Fragment,{children:[o(f,{sx:{"& > *":{borderBottom:"unset"}},children:[a(n,{align:"left",children:e.id}),a(n,{align:"left",children:e.code}),a(n,{align:"left",children:e.name}),a(n,{align:"left",children:e.items_count}),a(n,{align:"right",children:e.status=="active"?a(T,{variant:"outlined",onClick:()=>{q(e)},color:"success",size:"small",children:"Active"}):a(T,{variant:"outlined",onClick:()=>{j(e)},color:"error",size:"small",children:"Tidak Digunakan"})})]}),a(f,{children:a(n,{style:{paddingBottom:0,paddingTop:0},colSpan:10,children:a(Y,{in:r,timeout:"auto",unmountOnExit:!0,children:a(Z,{sx:{borderBottom:1},children:a($,{variant:"body2",gutterBottom:!0,component:"div",children:"No Extra Data"})})})})})]})}const b=async(t=null)=>{B(!0);const e=t||Object.fromEntries([...m.entries()]),r=await y.get("/corporates/"+u+"/formulariums",{params:e});B(!1),v(r.data)},g={fontWeight:"bold"},O=async t=>{await b(t),_(t)},z=(t,e)=>{const r=Object.fromEntries([...m.entries(),["page",e]]);b(r),_(r)};return d.exports.useEffect(()=>{b()},[]),o(F,{children:[a(F,{direction:"row",spacing:2,sx:{p:2},children:a(N,{onSearch:O})}),o(A,{children:[a(ta,{component:U,children:o(ra,{"aria-label":"collapsible table",children:[a(S,{children:o(f,{children:[a(n,{style:g,align:"left",width:50,children:"#"}),a(n,{style:g,align:"left",children:"Code"}),a(n,{style:g,align:"left",children:"Name"}),a(n,{style:g,align:"left",children:"Total Item"}),a(n,{style:g,align:"right",children:"Status"})]})}),E?a(S,{children:a(f,{children:a(n,{colSpan:8,align:"center",children:"Loading"})})}):l.data.length==0?a(S,{children:a(f,{children:a(n,{colSpan:8,align:"center",children:"No Data"})})}):a(S,{children:l.data.map(t=>a(L,{row:t},t.code))})]})}),a(ea,{paginationData:l,onPageChange:z})]})]})}function ma(){I();const{corporate_id:u}=R();return o(Q,{title:"Formularium",children:[a(M,{heading:"Formularium",links:[{name:"Corporates",href:"/corporates"},{name:"Corporate Name",href:"/corporates/"+u},{name:"Formularium",href:"/corporates/"+u+"/formularium"}]}),o(A,{children:[a(aa,{position:"formularium"}),a(na,{})]})]})}export{ma as default};
