import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-BWRPWl8p.js";import{i as r,t as i}from"./axios-Yyz76XvX.js";import{La as a,Wt as o}from"./endpoints-BWeG8ngA.js";import{t as s}from"./calendario-CKssedVC.js";import{Da as c,Ei as l,G as u,Li as d,Qt as f,Sn as p,W as m,da as h,ki as g,ma as _,wn as v}from"./index-DccLTdzK.js";import{t as y}from"./withRouter-CRkgdzqj.js";import{t as b}from"./PageHeader-DNnlanBD.js";import{t as x}from"./react-select.esm-B6s_VbxN.js";import{t as S}from"./query-string-D4ReIoyH.js";import{t as C}from"./maquinas-BxHBoChf.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,s]=(0,w.useState)(``),[u,m]=(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)(d,{children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(g,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,D.jsx)(h,{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)(d.Label,{children:[`Máquina: `,(0,D.jsx)(`code`,{children:`*`})]})}),(0,D.jsx)(h,{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)(h,{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)(d.Label,{children:[`Fecha de inicio: `,(0,D.jsx)(`code`,{children:`*`})]})}),(0,D.jsx)(h,{sm:12,md:8,lg:8,children:(0,D.jsx)(d.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)(h,{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)(d.Label,{children:[`Fecha de fin: `,(0,D.jsx)(`code`,{children:`*`})]})}),(0,D.jsx)(h,{sm:12,md:8,lg:8,children:(0,D.jsx)(d.Control,{type:`date`,value:o,onChange:e=>s(e.target.value)})})]}),(0,D.jsxs)(g,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,D.jsx)(h,{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)(d.Label,{children:`Observaciones:`})}),(0,D.jsx)(h,{sm:12,md:8,lg:8,children:(0,D.jsx)(d.Control,{as:`textarea`,placeholder:`Ingresa observaciones en caso de ser necesarias`,value:u,onChange:e=>m(e.target.value)})})]})]}),(0,D.jsx)(`div`,{className:`divSubmit`,children:(0,D.jsxs)(_,{variant:`success`,onClick:r=>{if(r.preventDefault(),!n||!i||!o)c.warning(`Datos incompletos`);else try{let r={maquina:n,fecha:{inicio:i,fin:o},motivo:u,estado:`true`};E(r).then(n=>{let{data:i}=n;c.success(`Mantenimiento a máquina registrado`),f(`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)(l,{icon:p}),` 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)([]),c=()=>{try{T().then(e=>{let{data:t}=e;o(t)}).catch(e=>{})}catch{}};(0,w.useEffect)(()=>{c()},[t]);let[l,d]=(0,w.useState)(!1),[f,p]=(0,w.useState)(null),[h,g]=(0,w.useState)(null),_=e=>{g(`Registar mantenimiento de máquina`),p(e),d(!0)};return(0,D.jsxs)(D.Fragment,{children:[r&&(0,D.jsx)(m,{}),(0,D.jsx)(b,{title:`Programa de mantenimiento de máquinas`,icon:v,onAddClick:()=>_((0,D.jsx)(O,{setShow:d,history:n})),addText:`Registrar`}),(0,D.jsx)(s,{eventosIniciales:a}),(0,D.jsx)(`div`,{className:`divTabla`}),(0,D.jsxs)(u,{show:l,onClose:()=>d(!1),maxWidth:`xl`,children:[(0,D.jsx)(u.Header,{closeButton:!0,onClose:()=>d(!1),children:h}),(0,D.jsx)(u.Body,{children:f})]})]})}var j=y(A);export{j as default};