import{H as $}from"./HeaderBreadcrumbs.da67f38c.js";import{P as A}from"./Page.4c1db0aa.js";import{al as w,bi as B,aQ as N,r as i,j as o,S as P,f as e,P as F,ar as b,aq as x,i as H,az as D,as as O}from"./index.8f299a7d.js";import{C as W}from"./CorporateTabNavigations.42a351a3.js";import{B as q}from"./BasePagination.56fc59df.js";import{C as j}from"./Card.1ec83a31.js";import{T as Q}from"./TableContainer.b8d5000e.js";import{T as G,a as g,b as f,c as s}from"./TableRow.d2ef76cd.js";function J(){w();const{corporate_id:l}=B(),[c,T]=N();i.exports.useState(null);const[k,_]=i.exports.useState(!0);i.exports.useState(0),i.exports.useState("idle");const[d,C]=i.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 L(a){const t=i.exports.useRef(null),[r,h]=i.exports.useState(""),S=n=>{var y;const u=(y=n.target.value)!=null?y:"";h(u)},v=n=>{n.preventDefault(),a.onSearch(r)};return i.exports.useEffect(()=>{var n;h((n=c.get("search"))!=null?n:"")},[c]),e("form",{onSubmit:v,style:{width:"100%"},children:e(O,{id:"search-input",ref:t,label:"Search",variant:"outlined",fullWidth:!0,onChange:S,value:r})})}function z(a){return b.useState(null),e(P,{direction:"row",spacing:2,sx:{p:2},children:e(L,{onSearch:I})})}function E(a){const{row:t}=a;b.useState(!1);const r=(h,S)=>{D.put(`/corporates/${l}/services/${h.service_code}`,{service_code:h.service_code,status:S}).then(v=>{C({...d,data:d.data.map(n=>{let u=n;return t.id==n.id&&(u.status=v.data.status),u})})})};return o(b.Fragment,{children:[o(f,{sx:{"& > *":{borderBottom:"unset"}},children:[e(s,{align:"left",children:t.service_code}),e(s,{align:"left",children:t.name}),o(s,{align:"right",children:[t.status=="active"&&e(x,{variant:"outlined",color:"success",size:"small",onClick:()=>{r(t,"inactive")},children:"Active"}),t.status=="inactive"&&e(x,{variant:"outlined",color:"error",size:"small",onClick:()=>{r(t,"active")},children:"Inactive"})]}),e(s,{align:"right",children:e(H,{to:`/corporates/${l}/services/${t.service_code}`,children:e(x,{variant:"outlined",color:"primary",size:"small",children:"Config"})})})]}),!1]})}const m=async(a=null)=>{_(!0);const t=a||Object.fromEntries([...c.entries()]),r=await D.get("/corporates/"+l+"/services",{params:t});_(!1),C(r.data)},p={fontWeight:"bold"},I=async a=>{await m({search:a}),T({search:a})},R=(a,t)=>{const r=Object.fromEntries([...c.entries(),["page",t]]);m(r),T(r)};return i.exports.useEffect(()=>{m()},[]),o(P,{children:[e(z,{}),o(j,{children:[e(Q,{component:F,children:o(G,{"aria-label":"collapsible table",children:[e(g,{children:o(f,{children:[e(s,{style:p,align:"left",children:"Code"}),e(s,{style:p,align:"left",children:"Service"}),e(s,{style:p,align:"right",width:30,children:"Status"}),e(s,{style:p,align:"right",width:30,children:"Action"})]})}),k?e(g,{children:e(f,{children:e(s,{colSpan:8,align:"center",children:"Loading"})})}):d.data.length==0?e(g,{children:e(f,{children:e(s,{colSpan:8,align:"center",children:"No Data"})})}):e(g,{children:d.data.map(a=>e(E,{row:a},a.id))})]})}),e(q,{paginationData:d,onPageChange:R})]})]})}function ae(){w();const{corporate_id:l}=B(),c="Services";return o(A,{title:c,children:[e($,{heading:c,links:[{name:"Corporates",href:"/corporates"},{name:"Corporate Name",href:"/corporates/"+l},{name:"Services",href:"/corporates/"+l+"/services"}]}),o(j,{children:[e(W,{position:"services"}),e(J,{})]})]})}export{ae as default};
