1import{j as e,U as ae,V as se,W as oe,Y as ne,Z as re,a7 as pe,B as N,a8 as fe,a9 as y,ac as Ce,aa as Ve,an as Le,ab as Fe,C as ie,g as te,h as le,i as ge,l as ce,r as m,s as T,m as Me,a as ze,E as ke}from"./index-DfOJmvz4.js";import{a as Be}from"./CondoDashboardLayout-vBp5D4FR.js";import{B as $}from"./badge-Dbl0Jwtm.js";import{I as D}from"./input-Vet5F-CU.js";import{b as _e,c as ve,T as U,d as v,e as be,a as b}from"./table-DfwkKR6X.js";import{D as Re,a as Ue,b as qe,e as Z}from"./dropdown-menu-By9cTOSf.js";import{S as G,a as J,b as Y,c as W,d as V}from"./select-CJff1OXZ.js";import{u as Ne,t as Se,F as we,a as j,b as u,c as p,d as f,e as _}from"./form-CGjVjtQi.js";import{T as De}from"./textarea-BWprJflG.js";import{C as He,i as $e}from"./condoDemoFillers-BYkB9Eu7.js";import{L as q}from"./loader-circle-rLXjDXa8.js";import{T as Ge,a as Je,b as je,c as ue}from"./tabs-Czrmf5jI.js";import{C as Ye}from"./checkbox-D-CdFUfS.js";import{P as K}from"./plus-BrPtK6Sd.js";import{f as Q}from"./format-9oAvKElA.js";import{U as We}from"./user-5KGpXtlR.js";import{P as Xe}from"./phone-BQczP6o_.js";import{M as Ze}from"./mail-D3nKZQgu.js";import{C as Ke}from"./calendar-Dq05LY-4.js";import{D as Qe}from"./dollar-sign-BqG8LMSI.js";import{C as ea}from"./circle-alert-C9ihB5Z4.js";import{e as aa}from"./es-DYyshBza.js";import{D as sa}from"./DeleteConfirmDialog-CGD4ovZb.js";import{C as oa}from"./CondoImportDialog-CKxro3Hh.js";import{U as na}from"./upload-C_kbLsjP.js";import{S as ra}from"./search-CuA8j5sK.js";import{U as ia}from"./users-BZXBZcrg.js";import{E as ta}from"./ellipsis-ChaP9twA.js";import{P as la}from"./pencil-BjX4drB7.js";import{T as ca}from"./trash-2-Br_Yo4vG.js";import"./useRoleCheck-14xyS_Q4.js";import"./RoleSwitcher-DEBS1NdH.js";import"./shield-CHS6FU5N.js";import"./briefcase-CcBOcOKF.js";import"./building-2-Bsxya_X5.js";import"./useTrashCount-Bj-0KmFa.js";import"./useQuery-BDlu7gBK.js";import"./logo-urvem-negro-BmAKGchK.js";import"./wrench-B2cA4B1h.js";import"./arrow-left-DHLt5dfU.js";import"./receipt-VIREyLjk.js";import"./wallet-DjkT_BNu.js";import"./file-chart-column-increasing-BxiwMYPJ.js";import"./flame-CFmkE-z6.js";import"./shield-alert-DNRO92Bf.js";import"./log-out-n4kWw_z0.js";import"./chevron-down-UE20mCyh.js";import"./external-link-4Fb_Vjed.js";import"./label-B-DNcIAs.js";import"./usePostalCodeLookup-dMZHUyAM.js";import"./alert-dialog-Bu3Oi65g.js";import"./filter-CZrgHDAK.js";import"./index-6ZOEkj60.js";import"./index-ivjWPsw3.js";import"./chevron-right-pbEstDsr.js";import"./check-XU_nGxmM.js";import"./index-BtGj9Er1.js";import"./flask-conical-CYR3TkvV.js";import"./differenceInCalendarDays-CyB0mb81.js";import"./getTimezoneOffsetInMilliseconds-vKak5z5M.js";import"./xlsx-CwpDMyS9.js";import"./index-C-llSyQH.js";import"./index-vseAPPBi.js";import"./alert-CxOnRn_V.js";import"./TemplatePreviewDialog-BTJUcum8.js";import"./scroll-area-DpAp9dfv.js";import"./file-spreadsheet-DTWg_2WK.js";import"./copy-C750C51G.js";import"./download-Cj4N-sj-.js";import"./sparkles-DXL9TkX8.js";import"./circle-check-C00U2u3l.js";import"./progress-DzZVASWB.js";import"./circle-x-BmzHflm5.js";import"./fileParsers-BCaZSfiz.js";const ee=[{value:"vigilante",label:"Vigilante"},{value:"portero",label:"Portero"},{value:"limpieza",label:"Personal de Limpieza"},{value:"jardinero",label:"Jardinero"},{value:"mantenimiento",label:"Mantenimiento General"},{value:"administrador",label:"Administrador"},{value:"contador",label:"Contador"},{value:"otro",label:"Otro"}],Te={0:"Domingo",1:"Lunes",2:"Martes",3:"Miércoles",4:"Jueves",5:"Viernes",6:"Sábado"},Pe={vacaciones:"Vacaciones",incapacidad:"Incapacidad",permiso:"Permiso"},da={pendiente:"Pendiente",aprobado:"Aprobado",rechazado:"Rechazado"},ma={pendiente:"bg-amber-100 text-amber-700",aprobado:"bg-green-100 text-green-700",rechazado:"bg-red-100 text-red-700"},ha=fe({nombre_completo:y().min(3,"El nombre debe tener al menos 3 caracteres"),puesto:y().min(1,"Selecciona un puesto"),telefono:y().optional(),email:y().email("Email inválido").optional().or(Ve("")),fecha_ingreso:y().optional(),salario:Ce.number().min(0).optional(),contacto_emergencia_nombre:y().optional(),contacto_emergencia_telefono:y().optional(),notas:y().optional()});function xa({open:a,onOpenChange:n,onSubmit:g,isSubmitting:l,editingStaff:o}){const r=Ne({resolver:Se(ha),defaultValues:o?{nombre_completo:o.nombre_completo,puesto:o.puesto,telefono:o.telefono||"",email:o.email||"",fecha_ingreso:o.fecha_ingreso||"",salario:o.salario||void 0,contacto_emergencia_nombre:o.contacto_emergencia_nombre||"",contacto_emergencia_telefono:o.contacto_emergencia_telefono||"",notas:o.notas||""}:{nombre_completo:"",puesto:"",telefono:"",email:"",fecha_ingreso:"",salario:void 0,contacto_emergencia_nombre:"",contacto_emergencia_telefono:"",notas:""}}),d=async i=>{await g(i),r.reset()};return e.jsx(ae,{open:a,onOpenChange:n,children:e.jsxs(se,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsxs(oe,{children:[e.jsx(ne,{children:o?"Editar Personal":"Nuevo Personal"}),e.jsx(re,{children:o?"Modifica los datos del empleado":"Registra un nuevo empleado de áreas comunes"})]}),e.jsx(we,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(d),className:"space-y-4",children:[e.jsx(He,{onFill:()=>r.reset($e())}),e.jsx(j,{control:r.control,name:"nombre_completo",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Nombre Completo *"}),e.jsx(f,{children:e.jsx(D,{placeholder:"Juan Pérez GarcÃa",...i})}),e.jsx(_,{})]})}),e.jsx(j,{control:r.control,name:"puesto",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Puesto *"}),e.jsxs(G,{onValueChange:i.onChange,value:i.value,children:[e.jsx(f,{children:e.jsx(J,{children:e.jsx(Y,{placeholder:"Selecciona un puesto"})})}),e.jsx(W,{position:"popper",className:"z-[9999]",children:ee.map(S=>e.jsx(V,{value:S.value,children:S.label},S.value))})]}),e.jsx(_,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:r.control,name:"telefono",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Teléfono"}),e.jsx(f,{children:e.jsx(D,{placeholder:"55 1234 5678",...i})}),e.jsx(_,{})]})}),e.jsx(j,{control:r.control,name:"email",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Email"}),e.jsx(f,{children:e.jsx(D,{type:"email",placeholder:"[email protected]",...i})}),e.jsx(_,{})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:r.control,name:"fecha_ingreso",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Fecha de Ingreso"}),e.jsx(f,{children:e.jsx(D,{type:"date",...i})}),e.jsx(_,{})]})}),e.jsx(j,{control:r.control,name:"salario",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Salario Mensual"}),e.jsx(f,{children:e.jsx(D,{type:"number",placeholder:"0.00",...i,value:i.value||""})}),e.jsx(_,{})]})})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",children:"Contacto de Emergencia"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:r.control,name:"contacto_emergencia_nombre",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Nombre"}),e.jsx(f,{children:e.jsx(D,{placeholder:"Familiar o conocido",...i})}),e.jsx(_,{})]})}),e.jsx(j,{control:r.control,name:"contacto_emergencia_telefono",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Teléfono"}),e.jsx(f,{children:e.jsx(D,{placeholder:"55 1234 5678",...i})}),e.jsx(_,{})]})})]})]}),e.jsx(j,{control:r.control,name:"notas",render:({field:i})=>e.jsxs(u,{children:[e.jsx(p,{children:"Notas"}),e.jsx(f,{children:e.jsx(De,{placeholder:"Observaciones adicionales...",rows:2,...i})}),e.jsx(_,{})]})}),e.jsxs(pe,{children:[e.jsx(N,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancelar"}),e.jsxs(N,{type:"submit",disabled:l,children:[l&&e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),o?"Guardar Cambios":"Registrar"]})]})]})})]})})}const ja=fe({dia_semana:Ce.number().min(0).max(6),hora_entrada:y().optional(),hora_salida:y().optional(),es_dia_descanso:Le()});function ua({open:a,onOpenChange:n,onSubmit:g,isSubmitting:l,existingDays:o}){const r=Ne({resolver:Se(ja),defaultValues:{dia_semana:1,hora_entrada:"08:00",hora_salida:"16:00",es_dia_descanso:!1}}),d=r.watch("es_dia_descanso"),i=async x=>{await g(x),r.reset()},S=Object.entries(Te).filter(([x])=>!o.includes(Number(x)));return e.jsx(ae,{open:a,onOpenChange:n,children:e.jsxs(se,{className:"max-w-sm",children:[e.jsxs(oe,{children:[e.jsx(ne,{children:"Agregar Horario"}),e.jsx(re,{children:"Define el horario para un dÃa de la semana"})]}),e.jsx(we,{...r,children:e.jsxs("form",{onSubmit:r.handleSubmit(i),className:"space-y-4",children:[e.jsx(j,{control:r.control,name:"dia_semana",render:({field:x})=>e.jsxs(u,{children:[e.jsx(p,{children:"DÃa *"}),e.jsxs(G,{onValueChange:w=>
1x.onChange(Number(w)),value:String(x.value),children:[e.jsx(f,{children:e.jsx(J,{children:e.jsx(Y,{placeholder:"Selecciona un dÃa"})})}),e.jsx(W,{position:"popper",className:"z-[9999]",children:S.map(([w,P])=>e.jsx(V,{value:w,children:P},w))})]}),e.jsx(_,{})]})}),e.jsx(j,{control:r.control,name:"es_dia_descanso",render:({field:x})=>e.jsxs(u,{className:"flex flex-row items-start space-x-3 space-y-0",children:[e.jsx(f,{children:e.jsx(Ye,{checked:x.value,onCheckedChange:x.onChange})}),e.jsx("div",{className:"space-y-1 leading-none",children:e.jsx(p,{children:"DÃa de descanso"})})]})}),!d&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:r.control,name:"hora_entrada",render:({field:x})=>e.jsxs(u,{children:[e.jsx(p,{children:"Entrada"}),e.jsx(f,{children:e.jsx(D,{type:"time",...x})}),e.jsx(_,{})]})}),e.jsx(j,{control:r.control,name:"hora_salida",render:({field:x})=>e.jsxs(u,{children:[e.jsx(p,{children:"Salida"}),e.jsx(f,{children:e.jsx(D,{type:"time",...x})}),e.jsx(_,{})]})})]}),e.jsxs(pe,{children:[e.jsx(N,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancelar"}),e.jsxs(N,{type:"submit",disabled:l||S.length===0,children:[l&&e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),"Agregar"]})]})]})})]})})}const pa=fe({fecha_inicio:y().min(1,"Fecha requerida"),fecha_fin:y().min(1,"Fecha requerida"),tipo:Fe(["vacaciones","incapacidad","permiso"]),motivo:y().optional()});function fa({open:a,onOpenChange:n,onSubmit:g,isSubmitting:l}){const o=Ne({resolver:Se(pa),defaultValues:{fecha_inicio:"",fecha_fin:"",tipo:"vacaciones",motivo:""}}),r=async d=>{await g(d),o.reset()};return e.jsx(ae,{open:a,onOpenChange:n,children:e.jsxs(se,{className:"max-w-sm",children:[e.jsxs(oe,{children:[e.jsx(ne,{children:"Nueva Ausencia"}),e.jsx(re,{children:"Registra vacaciones, incapacidad o permiso"})]}),e.jsx(we,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(r),className:"space-y-4",children:[e.jsx(j,{control:o.control,name:"tipo",render:({field:d})=>e.jsxs(u,{children:[e.jsx(p,{children:"Tipo *"}),e.jsxs(G,{onValueChange:d.onChange,value:d.value,children:[e.jsx(f,{children:e.jsx(J,{children:e.jsx(Y,{placeholder:"Selecciona el tipo"})})}),e.jsx(W,{position:"popper",className:"z-[9999]",children:Object.entries(Pe).map(([i,S])=>e.jsx(V,{value:i,children:S},i))})]}),e.jsx(_,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(j,{control:o.control,name:"fecha_inicio",render:({field:d})=>e.jsxs(u,{children:[e.jsx(p,{children:"Fecha Inicio *"}),e.jsx(f,{children:e.jsx(D,{type:"date",...d})}),e.jsx(_,{})]})}),e.jsx(j,{control:o.control,name:"fecha_fin",render:({field:d})=>e.jsxs(u,{children:[e.jsx(p,{children:"Fecha Fin *"}),e.jsx(f,{children:e.jsx(D,{type:"date",...d})}),e.jsx(_,{})]})})]}),e.jsx(j,{control:o.control,name:"motivo",render:({field:d})=>e.jsxs(u,{children:[e.jsx(p,{children:"Motivo"}),e.jsx(f,{children:e.jsx(De,{placeholder:"Descripción opcional...",rows:2,...d})}),e.jsx(_,{})]})}),e.jsxs(pe,{children:[e.jsx(N,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancelar"}),e.jsxs(N,{type:"submit",disabled:l,children:[l&&e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),"Registrar"]})]})]})})]})})}function ga({schedules:a,isLoading:n,onAdd:g}){return e.jsxs(ie,{children:[e.jsxs(te,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx(le,{className:"text-sm",children:"Horario Semanal"}),e.jsx(ge,{children:"Turnos y dÃas de descanso"})]}),e.jsxs(N,{size:"sm",onClick:g,children:[e.jsx(K,{className:"h-4 w-4 mr-1"}),"Agregar"]})]}),e.jsx(ce,{children:n?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):a.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"Sin horario definido"}):e.jsxs(_e,{children:[e.jsx(ve,{children:e.jsxs(U,{children:[e.jsx(v,{children:"DÃa"}),e.jsx(v,{children:"Entrada"}),e.jsx(v,{children:"Salida"}),e.jsx(v,{children:"Estado"})]})}),e.jsx(be,{children:a.map(l=>e.jsxs(U,{children:[e.jsx(b,{className:"font-medium",children:Te[l.dia_semana]}),e.jsx(b,{children:l.es_dia_descanso?"-":l.hora_entrada||"-"}),e.jsx(b,{children:l.es_dia_descanso?"-":l.hora_salida||"-"}),e.jsx(b,{children:l.es_dia_descanso?e.jsx($,{variant:"outline",children:"Descanso"}):e.jsx($,{className:"bg-green-100 text-green-700",children:"Laboral"})})]},l.id))})]})})]})}function _a({vacations:a,isLoading:n,onAdd:g,onUpdateStatus:l}){return e.jsxs(ie,{children:[e.jsxs(te,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx(le,{className:"text-sm",children:"Vacaciones y Ausencias"}),e.jsx(ge,{children:"Historial de permisos"})]}),e.jsxs(N,{size:"sm",onClick:g,children:[e.jsx(K,{className:"h-4 w-4 mr-1"}),"Solicitar"]})]}),e.jsx(ce,{children:n?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):a.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"Sin ausencias registradas"}):e.jsxs(_e,{children:[e.jsx(ve,{children:e.jsxs(U,{children:[e.jsx(v,{children:"Tipo"}),e.jsx(v,{children:"PerÃodo"}),e.jsx(v,{children:"Estado"}),e.jsx(v,{className:"w-[100px]",children:"Acciones"})]})}),e.jsx(be,{children:a.map(o=>e.jsxs(U,{children:[e.jsx(b,{className:"font-medium",children:Pe[o.tipo]||o.tipo}),e.jsxs(b,{className:"text-sm",children:[Q(new Date(o.fecha_inicio),"dd/MM/yy")," - ",Q(new Date(o.fecha_fin),"dd/MM/yy")]}),e.jsx(b,{children:e.jsx($,{className:ma[o.status],children:da[o.status]})}),e.jsx(b,{children:o.status==="pendiente"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsx(N,{size:"sm",variant:"ghost",className:"h-7 px-2 text-green-600",onClick:()=>l(o.id,"aprobado"),children:"â"}),e.jsx(N,{size:"sm",variant:"ghost",className:"h-7 px-2 text-red-600",onClick:()=>l(o.id,"rechazado"),children:"â"})]})})]},o.id))})]})})]})}function va({staff:a,open:n,onOpenChange:g}){var z;const[l,o]=m.useState("info"),[r,d]=m.useState([]),[i,S]=m.useState([]),[x,w]=m.useState(!1),[P,L]=m.useState(!1),[X,B]=m.useState(!1),[de,I]=m.useState(!1),[E,O]=m.useState(!1),me=((z=ee.find(t=>t.value===(a==null?void 0:a.puesto)))==null?void 0:z.label)||(a==null?void 0:a.puesto);m.useEffect(()=>{a&&n&&(F(),M())},[a,n]);const F=async()=>
1{if(a){w(!0);try{const{data:t,error:h}=await T.from("condominium_staff_schedules").select("*").eq("staff_id",a.id).order("dia_semana");if(h)throw h;d(t||[])}catch(t){console.error("Error fetching schedules:",t)}finally{w(!1)}}},M=async()=>{if(a){L(!0);try{const{data:t,error:h}=await T.from("condominium_staff_vacations").select("*").eq("staff_id",a.id).order("fecha_inicio",{ascending:!1});if(h)throw h;S(t||[])}catch(t){console.error("Error fetching vacations:",t)}finally{L(!1)}}},he=async t=>{if(a){O(!0);try{const{error:h}=await T.from("condominium_staff_schedules").insert({staff_id:a.id,dia_semana:t.dia_semana,hora_entrada:t.es_dia_descanso?null:t.hora_entrada,hora_salida:t.es_dia_descanso?null:t.hora_salida,es_dia_descanso:t.es_dia_descanso});if(h)throw h;F(),B(!1)}catch(h){console.error("Error adding schedule:",h)}finally{O(!1)}}},H=async t=>{if(a){O(!0);try{const{error:h}=await T.from("condominium_staff_vacations").insert({staff_id:a.id,fecha_inicio:t.fecha_inicio,fecha_fin:t.fecha_fin,tipo:t.tipo,motivo:t.motivo||null,status:"pendiente"});if(h)throw h;M(),I(!1)}catch(h){console.error("Error adding vacation:",h)}finally{O(!1)}}},xe=async(t,h)=>{try{const{error:k}=await T.from("condominium_staff_vacations").update({status:h}).eq("id",t);if(k)throw k;M()}catch(k){console.error("Error updating vacation status:",k)}};return a?e.jsxs(e.Fragment,{children:[e.jsx(ae,{open:n,onOpenChange:g,children:e.jsxs(se,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(oe,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-full bg-primary/10",children:e.jsx(We,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx(ne,{children:a.nombre_completo}),e.jsx(re,{children:me})]}),e.jsx($,{className:a.is_active?"bg-green-100 text-green-700":"bg-red-100 text-red-700",children:a.is_active?"Activo":"Inactivo"})]})}),e.jsxs(Ge,{value:l,onValueChange:o,children:[e.jsxs(Je,{className:"grid w-full grid-cols-3",children:[e.jsx(je,{value:"info",children:"Información"}),e.jsx(je,{value:"schedule",children:"Horarios"}),e.jsx(je,{value:"vacations",children:"Ausencias"})]}),e.jsxs(ue,{value:"info",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-3",children:[a.telefono&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Xe,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:a.telefono})]}),a.email&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ze,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:a.email})]}),a.fecha_ingreso&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ke,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{children:["Ingreso: ",Q(new Date(a.fecha_ingreso),"d 'de' MMMM yyyy",{locale:aa})]})]}),a.salario&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Qe,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{children:["Salario: $",a.salario.toLocaleString("es-MX",{minimumFractionDigits:2})]})]})]}),(a.contacto_emergencia_nombre||a.contacto_emergencia_telefono)&&e.jsxs(ie,{children:[e.jsx(te,{className:"pb-2",children:e.jsxs(le,{className:"text-sm flex items-center gap-2",children:[e.jsx(ea,{className:"h-4 w-4 text-amber-500"}),"Contacto de Emergencia"]})}),e.jsxs(ce,{className:"text-sm",children:[a.contacto_emergencia_nombre&&e.jsx("p",{children:a.contacto_emergencia_nombre}),a.contacto_emergencia_telefono&&e.jsx("p",{className:"text-muted-foreground",children:a.contacto_emergencia_telefono})]})]})]}),a.notas&&e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:"Notas"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.notas})]})]}),e.jsx(ue,{value:"schedule",className:"mt-4",children:e.jsx(ga,{schedules:r,isLoading:x,onAdd:()=>B(!0)})}),e.jsx(ue,{value:"vacations",className:"mt-4",children:e.jsx(_a,{vacations:i,isLoading:P,onAdd:()=>I(!0),onUpdateStatus:xe})})]})]})}),e.jsx(ua,{open:X,onOpenChange:B,onSubmit:he,isSubmitting:E,existingDays:r.map(t=>t.dia_semana)}),e.jsx(fa,{open:de,onOpenChange:I,onSubmit:H,isSubmitting:E})]}):null}async function ba(a,n,g){const l={nombre_completo:a.nombre_completo,puesto:a.puesto,telefono:a.telefono||null,email:a.email||null,fecha_ingreso:a.fecha_ingreso||null,salario:a.salario||null,contacto_emergencia_nombre:a.contacto_emergencia_nombre||null,contacto_emergencia_telefono:a.contacto_emergencia_telefono||null,notas:a.notas||null};if(g){const{error:o}=await T.from("condominium_staff").update({...l,updated_at:new Date().toISOString()}).eq("id",g.id);if(o)throw o;return"Personal actualizado"}else{const{error:o}=await T.from("condominium_staff").insert({...l,condominium_id:n});if(o)throw o;return"Personal registrado"}}async function Na(a){const{error:n}=await T.from("condominium_staff").delete().eq("id",a);if(n)throw n}async function Sa(a){const{error:n}=await T.from("condominium_staff").update({is_active:!a.is_active,fecha_baja:a.is_active?new Date().toISOString().split("T")[0]:null,updated_at:new Date().toISOString()}).eq("id",a.id);if(n)throw n;return a.is_active?"Personal dado de baja":"Personal reactivado"}function wa({condominiumId:a}){const{toast:n}=Me(),{isDemoMode:g,demoRole:l}=ze(),o=g&&l==="condominiumAdmin",[r,d]=m.useState([]),[i,S]=m.useState(!1),[x,w]=m.useState(!1),[P,L]=m.useState(null),[X,B]=m.useState(null),[de,I]=m.useState(!1),[E,O]=m.useState(null),[me,F]=m.useState(!1),[M,he]=m.useState(""),[H,xe]=m.useState("todos"),[z,t]=m.useState("activos"),[h,k]=m.useState(!1),R=m.useCallback(async()=>
1{if(o){const s=Be();d(s.map(c=>({...c,is_active:c.status==="activo",salario:c.salario_mensual||null,contacto_emergencia_nombre:null,contacto_emergencia_telefono:null,fecha_baja:null,updated_at:c.created_at})));return}S(!0);try{const{data:s,error:c}=await T.from("condominium_staff").select("*").eq("condominium_id",a).order("nombre_completo");if(c)throw c;d(s||[])}catch(s){n({title:"Error al cargar personal",description:s==null?void 0:s.message,variant:"destructive"})}finally{S(!1)}},[a,n,o]);m.useEffect(()=>{R()},[R]);const Ee=async s=>{F(!0);try{if(o){if(P)d(A=>A.map(C=>C.id===P.id?{...C,...s,updated_at:new Date().toISOString()}:C)),n({title:"Personal actualizado (Demo)"});else{const A={id:`demo-staff-${Date.now()}`,condominium_id:a,...s,is_active:!0,fecha_baja:null,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};d(C=>[A,...C]),n({title:"Personal registrado (Demo)"})}w(!1),L(null);return}const c=await ba(s,a,P);n({title:c}),R(),w(!1),L(null)}catch(c){n({title:"Error al guardar",description:c==null?void 0:c.message,variant:"destructive"})}finally{F(!1)}},Ae=async()=>{if(E){F(!0);try{if(o){d(s=>s.filter(c=>c.id!==E.id)),n({title:"Personal eliminado (Demo)"}),I(!1),O(null);return}await Na(E.id),n({title:"Personal eliminado"}),R(),I(!1),O(null)}catch(s){n({title:"Error al eliminar",description:s==null?void 0:s.message,variant:"destructive"})}finally{F(!1)}}},Ie=async s=>{try{if(o){d(A=>A.map(C=>C.id===s.id?{...C,is_active:!C.is_active}:C)),n({title:s.is_active?"Personal dado de baja (Demo)":"Personal reactivado (Demo)"});return}const c=await Sa(s);n({title:c}),R()}catch(c){n({title:"Error al actualizar",description:c==null?void 0:c.message,variant:"destructive"})}},ye=r.filter(s=>{const c=s.nombre_completo.toLowerCase().includes(M.toLowerCase())||s.puesto.toLowerCase().includes(M.toLowerCase()),A=H==="todos"||s.puesto===H,C=z==="todos"||z==="activos"&&s.is_active||z==="inactivos"&&!s.is_active;return c&&A&&C}),Oe=s=>{var c;return((c=ee.find(A=>A.value===s))==null?void 0:c.label)||s};return e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[e.jsxs(te,{children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(le,{children:"Personal"}),e.jsx(ge,{children:"Gestiona el personal de áreas comunes"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(N,{variant:"outline",onClick:()=>k(!0),children:[e.jsx(na,{className:"h-4 w-4 mr-2"})," Importar"]}),e.jsxs(N,{onClick:()=>w(!0),children:[e.jsx(K,{className:"h-4 w-4 mr-2"})," Nuevo Personal"]})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-3 pt-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ra,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(D,{placeholder:"Buscar por nombre o puesto...",value:M,onChange:s=>he(s.target.value),className:"pl-9"})]}),e.jsxs(G,{value:H,onValueChange:xe,children:[e.jsx(J,{className:"w-full md:w-[180px]",children:e.jsx(Y,{placeholder:"Puesto"})}),e.jsxs(W,{children:[e.jsx(V,{value:"todos",children:"Todos los puestos"}),ee.map(s=>e.jsx(V,{value:s.value,children:s.label},s.value))]})]}),e.jsxs(G,{value:z,onValueChange:t,children:[e.jsx(J,{className:"w-full md:w-[150px]",children:e.jsx(Y,{placeholder:"Estado"})}),e.jsxs(W,{children:[e.jsx(V,{value:"todos",children:"Todos"}),e.jsx(V,{value:"activos",children:"Activos"}),e.jsx(V,{value:"inactivos",children:"Inactivos"})]})]})]})]}),e.jsx(ce,{children:i?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(q,{className:"h-8 w-8 animate-spin mx-auto text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Cargando personal..."})]}):ye.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ia,{className:"h-12 w-12 text-muted-foreground/50 mx-auto mb-3"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:r.length===0?"No hay personal registrado aún":"No se encontró personal con los filtros aplicados"}),r.length===0&&e.jsxs(N,{variant:"outline",onClick:()=>w(!0),children:[e.jsx(K,{className:"h-4 w-4 mr-2"})," Registrar Personal"]})]}):e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(_e,{children:[e.jsx(ve,{children:e.jsxs(U,{children:[e.jsx(v,{children:"Nombre"}),e.jsx(v,{children:"Puesto"}),e.jsx(v,{children:"Teléfono"}),e.jsx(v,{children:"Ingreso"}),e.jsx(v,{children:"Estado"}),e.jsx(v,{className:"w-[60px]"})]})}),e.jsx(be,{children:ye.map(s=>e.jsxs(U,{children:[e.jsx(b,{className:"font-medium",children:s.nombre_completo}),e.jsx(b,{children:Oe(s.puesto)}),e.jsx(b,{children:s.telefono||"-"}),e.jsx(b,{children:s.fecha_ingreso?Q(new Date(s.fecha_ingreso),"dd/MM/yyyy"):"-"}),e.jsx(b,{children:e.jsx($,{className:s.is_active?"bg-green-100 text-green-700":"bg-red-100 text-red-700",children:s.is_active?"Activo":"Inactivo"})}),e.jsx(b,{children:e.jsxs(Re,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx(N,{variant:"ghost",size:"icon",children:e.jsx(ta,{className:"h-4 w-4"})})}),e.jsxs(qe,{align:"end",children:[e.jsxs(Z,{onClick:()=>B(s),children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Ver Detalles"]}),e.jsxs(Z,{onClick:()=>L(s),children:[e.jsx(la,{className:"h-4 w-4 mr-2"}),"Editar"]}),e.jsx(Z,{onClick:()=>Ie(s),children:s.is_active?"Dar de Baja":"Reactivar"}),e.jsxs(Z,{className:"text-destructive",onClick:()=>{O(s),I(!0)},children:[e.jsx(ca,{className:"h-4 w-4 mr-2"}),"Eliminar"]})]})]})})]},s.id))})]})})})]}),e.jsx(xa,{open:x||!!P,onOpenChange:s=>{s||(w(!1),L(null))},onSubmit:Ee,isSubmitting:me,editingStaff:P}),e.jsx(va,{staff:X,open:!!X,onOpenChange:s=>!s&&B(null)}),e.jsx(sa,{open:de,onOpenChange:I,onConfirm:Ae,title:"¿Eliminar personal?",description:`Se eliminará permanentemente a ${E==null?void 0:E.nombre_completo} y todos sus registros de horarios y ausencias.`}),e.jsx(oa,{open:h,onOpenChange:k,condominiumId:a,entityType:"condo_personal",entityLabel:"Personal",onImportComplete:R})]})}function $s({condoId:a}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-2xl font-bold text-[#e8e8e8]",children:"Personal"}),e.jsx(wa,{condominiumId:a})]})}export{$s as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.