import{a as e}from"./chunk-BNv3lrIs.js";import{n as t,t as n}from"./jsx-runtime-pmtNMKr4.js";import{n as r}from"./toast-hrvP3G3Q.js";import{t as i}from"./Button-_yTP2B6J.js";import{t as a}from"./Col-Cmv4fRfN.js";import{t as o}from"./load-HIf6x4Qy.js";import{A as s,Jn as c,Lt as l,Vi as u,bi as d,fi as f,kr as p,li as m}from"./index-CBXvBSuP.js";import{t as h}from"./PageHeader-C3X_ZaAc.js";import{t as g}from"./DataTable-BuE1Zp8A.js";import{r as _}from"./departamentos-Drpt6DSH.js";import{n as v,t as y}from"./maquinas-CJIaMIwu.js";var b=e(t(),1),x=n(),S=({setShow:e})=>{let[t,n]=(0,b.useState)(``),[o,s]=(0,b.useState)(``),[u,p]=(0,b.useState)(``),[h,g]=(0,b.useState)([]),y=()=>{try{_().then(e=>{let{data:t}=e;g(C(t))}).catch(e=>{})}catch{}};return(0,b.useEffect)(()=>{y()},[]),(0,x.jsx)(x.Fragment,{children:(0,x.jsx)(`div`,{style:{padding:`2%`},children:(0,x.jsxs)(d,{children:[(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(f,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,x.jsx)(a,{sm:12,md:4,lg:4,className:`d-flex align-items-end justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,x.jsxs)(d.Label,{children:[`Nombre: `,(0,x.jsx)(`code`,{children:`*`})]})}),(0,x.jsx)(a,{sm:12,md:8,lg:8,children:(0,x.jsx)(d.Control,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Ingresa el nombre de la máquina`})})]}),(0,x.jsxs)(f,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,x.jsx)(a,{sm:12,md:4,lg:4,className:`d-flex align-items-end justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,x.jsxs)(d.Label,{children:[`Departamento: `,(0,x.jsx)(`code`,{children:`*`})]})}),(0,x.jsx)(a,{sm:12,md:8,lg:8,children:(0,x.jsxs)(d.Control,{as:`select`,value:o,onChange:e=>s(e.target.value),children:[(0,x.jsx)(`option`,{value:``,children:`Seleccionar departamento`}),h.map((e,t)=>(0,x.jsx)(`option`,{value:e.nombre,children:e.nombre}))]})})]}),(0,x.jsxs)(f,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,x.jsx)(a,{sm:12,md:4,lg:4,className:`d-flex align-items-start justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,x.jsx)(d.Label,{children:`Descripción:`})}),(0,x.jsx)(a,{sm:12,md:8,lg:8,children:(0,x.jsx)(d.Control,{as:`textarea`,placeholder:`Ingresa descripción`,value:u,onChange:e=>p(e.target.value)})})]})]}),(0,x.jsx)(`div`,{className:`divSubmit`,children:(0,x.jsxs)(i,{variant:`success`,onClick:n=>{if(n.preventDefault(),!t||!o)r.warning(`Datos incompletos`);else try{let n={nombre:t,descripcion:u,departamento:o,estado:`true`};v(n).then(t=>{let{data:i}=t;l(`Se ha registrado la maquina `+n.recibio,n),r.success(i.mensaje),e(!1)})}catch(e){console.log(e)}},children:[(0,x.jsx)(m,{icon:c}),` Registrar`]})})]})})})};function C(e){let t=[];return e.forEach(e=>{t.push({id:e._id,nombre:e.nombre})}),t}var w=()=>{let[e,t]=(0,b.useState)(!0);(0,b.useEffect)(()=>{setTimeout(()=>{t(!1)},500)},[]);let[n,r]=(0,b.useState)(!1),[i,a]=(0,b.useState)(null),[c,l]=(0,b.useState)(null),d=e=>{l(`Registrar máquinas`),a(e),r(!0)},f=[{name:`ID`,selector:e=>e.id,omit:!0},{name:`NOMBRE`,selector:e=>e.nombre,sortable:!0},{name:`DEPARTAMENTO`,selector:e=>e.departamento,sortable:!0},{name:`DESCRIPCIÓN`,selector:e=>e.descripcion,sortable:!0},{name:`STATUS`,cell:e=>(0,x.jsx)(u,{bg:e.estado==`true`?`success`:`danger`,children:e.estado==`true`?`Activo`:`Inhabilitado`}),sortable:!0}],[m,_]=(0,b.useState)([]),v=()=>{try{y().then(e=>{let{data:t}=e;t&&_(T(t))}).catch(e=>{})}catch{}};return(0,b.useEffect)(()=>{v()},[]),(0,x.jsxs)(x.Fragment,{children:[e&&(0,x.jsx)(o,{}),(0,x.jsx)(h,{title:`Máquinas`,icon:p,onAddClick:()=>d((0,x.jsx)(S,{setShow:r})),addText:`Registrar`}),(0,x.jsx)(`div`,{children:(0,x.jsx)(`div`,{className:`divTabla`,children:(0,x.jsx)(g,{datos:m,columnas:f})})}),(0,x.jsx)(`div`,{className:`divTabla`}),(0,x.jsxs)(s,{show:n,onClose:()=>r(!1),maxWidth:`xl`,children:[(0,x.jsx)(s.Header,{closeButton:!0,onClose:()=>r(!1),children:c}),(0,x.jsx)(s.Body,{children:i})]})]})};function T(e){let t=[];return e.forEach(e=>{t.push({id:e._id,nombre:e.nombre,descripcion:e.descripcion,departamento:e.departamento,estado:e.estado})}),t}export{w as default};