import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-BWRPWl8p.js";import{Da as r,Ei as i,G as a,Kr as o,Li as s,Qt as c,W as l,da as u,dr as d,ha as f,ki as p,ma as m}from"./index-DccLTdzK.js";import{t as h}from"./PageHeader-DNnlanBD.js";import{t as g}from"./DataTable-KLBE0uXO.js";import{r as _}from"./departamentos-NHlcDrlT.js";import{n as v,t as y}from"./maquinas-BxHBoChf.js";var b=e(t(),1),x=n(),S=({setShow:e})=>{let[t,n]=(0,b.useState)(``),[a,o]=(0,b.useState)(``),[l,f]=(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)(s,{children:[(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,x.jsx)(u,{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)(s.Label,{children:[`Nombre: `,(0,x.jsx)(`code`,{children:`*`})]})}),(0,x.jsx)(u,{sm:12,md:8,lg:8,children:(0,x.jsx)(s.Control,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Ingresa el nombre de la máquina`})})]}),(0,x.jsxs)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,x.jsx)(u,{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)(s.Label,{children:[`Departamento: `,(0,x.jsx)(`code`,{children:`*`})]})}),(0,x.jsx)(u,{sm:12,md:8,lg:8,children:(0,x.jsxs)(s.Control,{as:`select`,value:a,onChange:e=>o(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)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,x.jsx)(u,{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)(s.Label,{children:`Descripción:`})}),(0,x.jsx)(u,{sm:12,md:8,lg:8,children:(0,x.jsx)(s.Control,{as:`textarea`,placeholder:`Ingresa descripción`,value:l,onChange:e=>f(e.target.value)})})]})]}),(0,x.jsx)(`div`,{className:`divSubmit`,children:(0,x.jsxs)(m,{variant:`success`,onClick:n=>{if(n.preventDefault(),!t||!a)r.warning(`Datos incompletos`);else try{let n={nombre:t,descripcion:l,departamento:a,estado:`true`};v(n).then(t=>{let{data:i}=t;c(`Se ha registrado la maquina `+n.recibio,n),r.success(i.mensaje),e(!1)})}catch(e){console.log(e)}},children:[(0,x.jsx)(i,{icon:d}),` 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,s]=(0,b.useState)(null),[c,u]=(0,b.useState)(null),d=e=>{u(`Registrar máquinas`),s(e),r(!0)},p=[{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)(f,{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)(l,{}),(0,x.jsx)(h,{title:`Máquinas`,icon:o,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:p})})}),(0,x.jsx)(`div`,{className:`divTabla`}),(0,x.jsxs)(a,{show:n,onClose:()=>r(!1),maxWidth:`xl`,children:[(0,x.jsx)(a.Header,{closeButton:!0,onClose:()=>r(!1),children:c}),(0,x.jsx)(a.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};