import{a as e}from"./chunk-BNv3lrIs.js";import{n as t,t as n}from"./jsx-runtime-pmtNMKr4.js";import{i as r,t as i}from"./axios-Ba4xKhTU.js";import{La as a,Wt as o}from"./endpoints-DlZlVT68.js";import{n as s}from"./toast-hrvP3G3Q.js";import{t as c}from"./Button-_yTP2B6J.js";import{t as l}from"./calendario-CYAmrXPS.js";import{t as u}from"./Col-Cmv4fRfN.js";import{t as d}from"./load-HIf6x4Qy.js";import{A as f,Lt as p,an as m,bi as h,fi as g,li as _,sn as v}from"./index-CBXvBSuP.js";import{t as y}from"./withRouter-BfV3B9Vo.js";import{t as b}from"./PageHeader-C3X_ZaAc.js";import{t as x}from"./react-select.esm-Bc2Lyozz.js";import{t as S}from"./query-string-B0XJl1mO.js";import{t as C}from"./maquinas-CJIaMIwu.js";var w=e(t(),1);async function T(){return await i.get(r+o,{headers:{Accept:`application/json`,"Content-Type":`application/json`}})}async function E(e){return await i.post(r+a,e,{headers:{Accept:`application/json`,"Content-Type":`application/json`}})}var D=n(),O=({setShow:e,history:t})=>{let[n,r]=(0,w.useState)(null),[i,a]=(0,w.useState)(``),[o,l]=(0,w.useState)(``),[d,f]=(0,w.useState)(``),[v,y]=(0,w.useState)([]),b=()=>{try{C().then(e=>{let{data:t}=e;y(k(t))}).catch(e=>{})}catch{}};(0,w.useEffect)(()=>{b()},[]);let T=e=>{r(e.value)};return(0,D.jsx)(`div`,{style:{padding:`2%`},children:(0,D.jsxs)(h,{children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(g,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,D.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,D.jsxs)(h.Label,{children:[`Máquina: `,(0,D.jsx)(`code`,{children:`*`})]})}),(0,D.jsx)(u,{sm:12,md:8,lg:8,children:(0,D.jsx)(x,{options:v,isSearchable:!0,placeholder:`Seleccionar...`,onChange:e=>T(e)})})]}),(0,D.jsxs)(g,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,D.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,D.jsxs)(h.Label,{children:[`Fecha de inicio: `,(0,D.jsx)(`code`,{children:`*`})]})}),(0,D.jsx)(u,{sm:12,md:8,lg:8,children:(0,D.jsx)(h.Control,{type:`date`,value:i,onChange:e=>a(e.target.value)})})]}),(0,D.jsxs)(g,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,D.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,D.jsxs)(h.Label,{children:[`Fecha de fin: `,(0,D.jsx)(`code`,{children:`*`})]})}),(0,D.jsx)(u,{sm:12,md:8,lg:8,children:(0,D.jsx)(h.Control,{type:`date`,value:o,onChange:e=>l(e.target.value)})})]}),(0,D.jsxs)(g,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,D.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,D.jsx)(h.Label,{children:`Observaciones:`})}),(0,D.jsx)(u,{sm:12,md:8,lg:8,children:(0,D.jsx)(h.Control,{as:`textarea`,placeholder:`Ingresa observaciones en caso de ser necesarias`,value:d,onChange:e=>f(e.target.value)})})]})]}),(0,D.jsx)(`div`,{className:`divSubmit`,children:(0,D.jsxs)(c,{variant:`success`,onClick:r=>{if(r.preventDefault(),!n||!i||!o)s.warning(`Datos incompletos`);else try{let r={maquina:n,fecha:{inicio:i,fin:o},motivo:d,estado:`true`};E(r).then(n=>{let{data:i}=n;s.success(`Mantenimiento a máquina registrado`),p(`Se ha registrado el mantenimiento para la maquina `+r.maquina,r),t({search:S.stringify(``)}),e(!1)})}catch(e){console.log(e)}},children:[(0,D.jsx)(_,{icon:m}),` Registrar`]})})]})})},k=e=>e.map(e=>({value:e.nombre+` - `+e.departamento,label:e.nombre+` - `+e.departamento}));function A(e){let{location:t,history:n}=e,[r,i]=(0,w.useState)(!0);(0,w.useEffect)(()=>{setTimeout(()=>{i(!1)},500)},[]);let[a,o]=(0,w.useState)([]),s=()=>{try{T().then(e=>{let{data:t}=e;o(t)}).catch(e=>{})}catch{}};(0,w.useEffect)(()=>{s()},[t]);let[c,u]=(0,w.useState)(!1),[p,m]=(0,w.useState)(null),[h,g]=(0,w.useState)(null),_=e=>{g(`Registar mantenimiento de máquina`),m(e),u(!0)};return(0,D.jsxs)(D.Fragment,{children:[r&&(0,D.jsx)(d,{}),(0,D.jsx)(b,{title:`Programa de mantenimiento de máquinas`,icon:v,onAddClick:()=>_((0,D.jsx)(O,{setShow:u,history:n})),addText:`Registrar`}),(0,D.jsx)(l,{eventosIniciales:a}),(0,D.jsx)(`div`,{className:`divTabla`}),(0,D.jsxs)(f,{show:c,onClose:()=>u(!1),maxWidth:`xl`,children:[(0,D.jsx)(f.Header,{closeButton:!0,onClose:()=>u(!1),children:h}),(0,D.jsx)(f.Body,{children:p})]})]})}var j=y(A);export{j as default};