import{a as e}from"./chunk-BNv3lrIs.js";import{n as t,t as n}from"./jsx-runtime-pmtNMKr4.js";import{t as r}from"./Col-Cmv4fRfN.js";import{t as i}from"./load-HIf6x4Qy.js";import{A as a,bi as o,fi as s,rn as c}from"./index-CBXvBSuP.js";import{t as l}from"./withRouter-BfV3B9Vo.js";import{r as u}from"./cursos-CsTUaQoN.js";import{n as d}from"./asistencia-BcBPqwcr.js";import{t as f}from"./PageHeader-C3X_ZaAc.js";import{t as p}from"./DataTable-BuE1Zp8A.js";var m=e(t(),1),h=n();function g(e){let{location:t}=e;function n(e){let t=new Date().getFullYear(),n=new Date(t,0,1),r=n.getDay()-1,i=new Date(t,0,1+(7-n.getDay())),a=new Date(i);a.setDate(i.getDate()+(e-1)*7);let o=new Date(a);o.setDate(a.getDate()-r+1);let s=new Date(o);return s.setDate(o.getDate()+13),{year:t,monday:o,sunday:s}}let l=new Date,g=Math.floor((l-new Date(l.getFullYear(),0,0))/864e5),[y,b]=(0,m.useState)(Math.ceil((g+1)/7-1)),{year:x,monday:S,sunday:C}=n(y),w=[{id:1,nombre:`Lunes`},{id:2,nombre:`Martes`},{id:3,nombre:`Miércoles`},{id:4,nombre:`Jueves`},{id:5,nombre:`Viernes`},{id:6,nombre:`Sábado`},{id:7,nombre:`Domingo`}],[T,E]=(0,m.useState)(!0);(0,m.useEffect)(()=>{setTimeout(()=>{E(!1)},500)},[]);let[D,O]=(0,m.useState)([]),[k,A]=(0,m.useState)([]);(0,m.useEffect)(()=>{j(),M()},[t,y]);let j=()=>{try{u().then(e=>{let{data:t}=e;O(_(t))}).catch(e=>{})}catch{}},M=()=>{try{d(S.toISOString().split(`T`)[0],C.toISOString().split(`T`)[0]).then(e=>{let{data:t}=e;A(v(t))}).catch(e=>{})}catch{}};console.log(k);let[N,P]=(0,m.useState)(!1),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)(null),z=[{name:`Empleado`,selector:e=>e.empleado,sortable:!0,wrap:!0},...w.map(e=>({name:e.nombre,selector:t=>{let n=t.asistenciaPorDia.find(t=>t.diaSemana===e.id);return n?n.asistencia:0},sortable:!0}))];return(0,h.jsxs)(h.Fragment,{children:[T&&(0,h.jsx)(i,{}),(0,h.jsx)(r,{sm:12,md:6,lg:6,children:(0,h.jsxs)(s,{children:[(0,h.jsx)(r,{sm:12,md:3,lg:3,children:(0,h.jsx)(o.Label,{children:`Selecciona una quincena:`})}),(0,h.jsx)(r,{children:(0,h.jsxs)(o.Control,{as:`select`,value:y,onChange:e=>b(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Selecciona`}),[...Array(52).keys()].map(e=>{let{monday:t,sunday:r}=n(e+1);return(0,h.jsx)(`option`,{value:e+1,children:`${t.toISOString().split(`T`)[0]} - ${r.toISOString().split(`T`)[0]}`},e+1)})]})})]})}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(f,{title:`Matriz de Asistencia de Empleados`,icon:c}),(0,h.jsx)(`div`,{className:`divTabla`,children:(0,h.jsx)(p,{datos:k,columnas:z})})]}),(0,h.jsxs)(a,{show:N,onClose:()=>P(!1),maxWidth:`xl`,children:[(0,h.jsx)(a.Header,{closeButton:!0,onClose:()=>P(!1),children:L}),(0,h.jsx)(a.Body,{children:F})]})]})}function _(e){return e.map(e=>({id:e._id,nombre:e.nombre,tipo:e.tipo,descripcion:e.descripcion,fecha:e.fecha,estado:e.estado}))}function v(e){return e.map(e=>({empleado:e.empleado,asistenciaPorDia:e.asistenciaPorDia.map(e=>({asistencia:e.asistencia,diaSemana:e.diaSemana}))}))}var y=l(g);export{y as default};