1import{r as d,s as v,j as e,B as T,c as N}from"./index-rReZfawE.js";import{C as U}from"./card-CHBfc5C_.js";import{I as u}from"./input-DL41uuIJ.js";import{L as J}from"./label-DIIn_Psu.js";import{T as B}from"./textarea-B_2I1DNs.js";import{S as $,a as q,b as I,c as F,d as w}from"./select-P9RDE-7H.js";import{D as Q,a as X,b as Y,c as K,d as W,e as Z}from"./dialog-DOG8t7e7.js";import{A as ee,a as ae,b as se,c as te,d as re,e as le,f as oe,g as ne}from"./alert-dialog-3RZnbcnj.js";import{B as ie}from"./badge-BnencD3h.js";import{t as x}from"./index-Cucp40tT.js";import{l as M}from"./adminActivity-DJpB1D86.js";import{B as ce}from"./briefcase-Dcxe2P6S.js";import{P as de}from"./plus-C2c2RntF.js";import{B as me}from"./building-2-C1dOPadN.js";import{c as P}from"./createLucideIcon-i-OpiFVS.js";import{G as ue}from"./graduation-cap-BPnC-Ut1.js";import{U as V}from"./users-CkpiRgpK.js";import{S as he}from"./search-joQkk7yT.js";import{X as pe}from"./x-CMtRwf98.js";import{L as G}from"./loader-circle-Coxp2__h.js";import{P as xe}from"./pencil-JU3cAcu2.js";import{T as ge}from"./trash-2-Bkwsfb7h.js";import{M as fe}from"./mail-Bt6J5_Vj.js";import{P as je}from"./phone-S7f8Oyha.js";import"./index-0ofysC_V.js";import"./index-D-NOk57k.js";import"./index-XuE39c_t.js";import"./index-DD_wpX4x.js";import"./chevron-down-D0ylB38w.js";import"./check-BHev5bnP.js";import"./chevron-up-CeJxaGZI.js";import"./index-fFsEnNlU.js";const be=[["path",{d:"M18 20a6 6 0 0 0-12 0",key:"1qehca"}],["circle",{cx:"12",cy:"10",r:"4",key:"1h16sb"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],ye=P("circle-user-round",be);const ve=[["path",{d:"M17.596 12.768a2 2 0 1 0 2.829-2.829l-1.768-1.767a2 2 0 0 0 2.828-2.829l-2.828-2.828a2 2 0 0 0-2.829 2.828l-1.767-1.768a2 2 0 1 0-2.829 2.829z",key:"9m4mmf"}],["path",{d:"m2.5 21.5 1.4-1.4",key:"17g3f0"}],["path",{d:"m20.1 3.9 1.4-1.4",key:"1qn309"}],["path",{d:"M5.343 21.485a2 2 0 1 0 2.829-2.828l1.767 1.768a2 2 0 1 0 2.829-2.829l-6.364-6.364a2 2 0 1 0-2.829 2.829l1.768 1.767a2 2 0 0 0-2.828 2.829z",key:"1t2c92"}],["path",{d:"m9.6 14.4 4.8-4.8",key:"6umqxw"}]],Ne=P("dumbbell",ve);const _e=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],Ce=P("store",_e),E=[{key:"directiva",label:"Directiva",icon:me,accent:"from-granate to-granate/60",dot:"bg-granate"},{key:"jugadoras",label:"Jugadoras",icon:Ne,accent:"from-rose-600 to-rose-400",dot:"bg-rose-500"},{key:"cuerpo_tecnico",label:"Cuerpo técnico",icon:ye,accent:"from-blue-600 to-blue-400",dot:"bg-blue-500"},{key:"cadetes",label:"Entrenadores cadetes",icon:ue,accent:"from-emerald-600 to-emerald-400",dot:"bg-emerald-500"},{key:"empleados",label:"Empleados",icon:Ce,accent:"from-amber-600 to-amber-400",dot:"bg-amber-500"},{key:"otros",label:"Otros",icon:V,accent:"from-slate-600 to-slate-400",dot:"bg-slate-500"}];function we(t){return E.find(r=>r.key===t)??E[E.length-1]}const R={category:"directiva",full_name:"",role_title:"",email:"",phone:"",dni:"",birth_date:"",address:"",iban:"",contract_type:"",contract_start:"",contract_end:"",salary:"",salary_period:"mensual",conditions:"",notes:""};function oa(){const[t,r]=d.useState([]),[h,c]=d.useState(!0),[s,f]=d.useState(""),[m,_]=d.useState("all"),[n,k]=d.use
1State(!1),[a,j]=d.useState(null),[g,b]=d.useState(null);d.useEffect(()=>{let l=!0;return(async()=>{c(!0);const{data:o,error:p}=await v.from("employees").select("*").order("created_at",{ascending:!1});l&&(p&&x.error("No se pudieron cargar los empleados",{description:p.message}),r(o??[]),c(!1))})(),()=>{l=!1}},[]),d.useEffect(()=>{const l=v.channel("employees_changes").on("postgres_changes",{event:"*",schema:"public",table:"employees"},o=>{r(p=>{if(o.eventType==="INSERT"){const y=o.new;return p.some(C=>C.id===y.id)?p:[y,...p]}if(o.eventType==="UPDATE"){const y=o.new;return p.map(C=>C.id===y.id?y:C)}if(o.eventType==="DELETE"){const y=o.old;return p.filter(C=>C.id!==y.id)}return p})}).subscribe();return()=>{v.removeChannel(l)}},[]);const L=d.useMemo(()=>{const l={};for(const o of t)l[o.category]=(l[o.category]??0)+1;return l},[t]),S=d.useMemo(()=>{const l=s.trim().toLowerCase();return t.filter(o=>m!=="all"&&o.category!==m?!1:l?[o.full_name,o.role_title,o.email,o.phone,o.dni,o.address,o.contract_type,o.conditions,o.notes].filter(Boolean).join(" ").toLowerCase().includes(l):!0)},[t,m,s]);function D(){j(null),k(!0)}function z(l){j(l),k(!0)}async function H(l){const{error:o}=await v.from("employees").delete().eq("id",l.id);if(o){x.error("No se pudo eliminar",{description:o.message});return}x.success(`${l.full_name} eliminado`),M({detail:`employees:delete:${l.id}:${l.full_name}`}),b(null)}return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("header",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold tracking-tight flex items-center gap-2",children:[e.jsx(ce,{className:"h-6 w-6 sm:h-7 sm:w-7"})," Empleados"]}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground mt-1",children:"Directiva, jugadoras, cuerpo técnico y demás personas del club â con todos sus datos, contratos y condiciones. Cambios en tiempo real."})]}),e.jsxs(T,{onClick:D,className:"shrink-0",children:[e.jsx(de,{className:"h-4 w-4 mr-1"})," Añadir persona"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(O,{label:"Todas",count:t.length,active:m==="all",onClick:()=>_("all")}),E.map(l=>e.jsx(O,{label:l.label,count:L[l.key]??0,active:m===l.key,dot:l.dot,onClick:()=>_(l.key)},l.key))]}),e.jsxs("div",{className:"relative",children:[e.jsx(he,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(u,{value:s,onChange:l=>f(l.target.value),placeholder:"Buscar por nombre, rol, email, teléfonoâ¦",className:"pl-9"}),s&&e.jsx("button",{onClick:()=>f(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground","aria-label":"Limpiar",children:e.jsx(pe,{className:"h-4 w-4"})})]}),h?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-8 justify-center",children:[e.jsx(G,{className:"h-4 w-4 animate-spin"})," Cargando empleadosâ¦"]}):S.length===0?e.jsxs(U,{className:"p-8 text-center",children:[e.jsx(V,{className:"h-10 w-10 mx-auto text-muted-foreground/60 mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.length===0?'TodavÃa no hay nadie. Pulsa "Añadir persona" para empezar.':"Ningún resultado con esos filtros."})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-4",children:S.map(l=>e.jsx(ke,{e:l,onEdit:()=>z(l),onDelete:()=>b(l)},l.id))}),e.jsx(Ee,{open:n,editing:a,onOpenChange:k,defaultCategory:m!=="all"?m:"directiva"}),e.jsx(ee,{open:!!g,onOpenChange:l=>!l&&b(null),children:e.jsxs(ae,{children:[e.jsxs(se,{children:[e.jsxs(te,{children:["¿Eliminar a ",g?.full_name,"?"]}),e.jsx(re,{children:"Se borrarán todos sus datos permanentemente. Esta acción no se puede deshacer."})]}),e.jsxs(le,{children:[e.jsx(oe,{children:"Cancelar"}),e.jsx(ne,{onClick:()=>g&&H(g),className:"bg-rose-600 hover:bg-rose-700",children:"Eliminar"})]})]})})]})}function O({label:t,count:r,active:h,dot:c,onClick:s}){return e.jsxs("button",{onClick:s,className:N("inline-flex items-center gap-2 px-3 py-1.5 rounded-full border text-xs sm:text-sm font-medium transition-all",h?"bg-granate text-white border-granate shadow-sm":"bg-card hover:bg-muted border-border text-foreground
1/80"),children:[c&&e.jsx("span",{className:N("h-2 w-2 rounded-full",c)}),t,e.jsx("span",{className:N("tabular-nums text-[10px] px-1.5 py-0.5 rounded-full",h?"bg-white/20":"bg-muted"),children:r})]})}function ke({e:t,onEdit:r,onDelete:h}){const c=we(t.category),s=c.icon,f=t.full_name.split(/\s+/).slice(0,2).map(m=>m[0]?.toUpperCase()??"").join("");return e.jsxs(U,{className:"overflow-hidden group hover:shadow-md transition-shadow",children:[e.jsx("div",{className:N("h-1.5 bg-gradient-to-r",c.accent)}),e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:N("h-11 w-11 rounded-full flex items-center justify-center text-white font-bold text-sm shrink-0 shadow-sm","bg-gradient-to-br",c.accent),children:f||e.jsx(s,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold truncate",children:t.full_name}),t.role_title&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:t.role_title}),e.jsx("div",{className:"flex items-center gap-1.5 mt-1.5",children:e.jsxs(ie,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4 gap-1",children:[e.jsx("span",{className:N("h-1.5 w-1.5 rounded-full",c.dot)}),c.label]})})]}),e.jsxs("div",{className:"flex flex-col gap-1 shrink-0 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:r,className:"p-1.5 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground","aria-label":"Editar",children:e.jsx(xe,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:h,className:"p-1.5 rounded-md hover:bg-rose-50 dark:hover:bg-rose-950/30 text-muted-foreground hover:text-rose-600","aria-label":"Eliminar",children:e.jsx(ge,{className:"h-3.5 w-3.5"})})]})]}),(t.email||t.phone)&&e.jsxs("div",{className:"mt-3 space-y-1 text-xs",children:[t.email&&e.jsxs("a",{href:`mailto:${t.email}`,className:"flex items-center gap-1.5 text-muted-foreground hover:text-granate truncate",children:[e.jsx(fe,{className:"h-3 w-3 shrink-0"})," ",e.jsx("span",{className:"truncate",children:t.email})]}),t.phone&&e.jsxs("a",{href:`tel:${t.phone}`,className:"flex items-center gap-1.5 text-muted-foreground hover:text-granate",children:[e.jsx(je,{className:"h-3 w-3 shrink-0"})," ",t.phone]})]}),(t.salary||t.contract_type)&&e.jsxs("div",{className:"mt-3 pt-3 border-t flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:[t.contract_type&&e.jsxs("span",{children:["ð ",t.contract_type]}),t.salary!=null&&e.jsxs("span",{children:["ð¶ ",Number(t.salary).toLocaleString("es-ES")," ⬠",t.salary_period?`/ ${t.salary_period}`:""]})]})]})]})}function Ee({open:t,editing:r,onOpenChange:h,defaultCategory:c}){const[s,f]=d.useState(R),[m,_]=d.useState(!1);d.useEffect(()=>{t&&f(r?{category:r.category,full_name:r.full_name,role_title:r.role_title??"",email:r.email??"",phone:r.phone??"",dni:r.dni??"",birth_date:r.birth_date??"",address:r.address??"",iban:r.iban??"",contract_type:r.contract_type??"",contract_start:r.contract_start??"",contract_end:r.contract_end??"",salary:r.salary!=null?String(r.salary):"",salary_period:r.salary_period??"mensual",conditions:r.conditions??"",notes:r.notes??""}:{...R,category:c})},[t,r,c]);function n(a,j){f(g=>({...g,[a]:j}))}async function k(){const a=s.full_name.trim();if(!a){x.error("El nombre es obligatorio");return}if(a.length>200){x.error("El nombre es demasiado largo");return}const j=s.salary.trim()?Number(s.salary.replace(",",".")):null;if(j!=null&&Number.isNaN(j)){x.error("El salario debe ser un número");return}const g={category:s.category,full_name:a,role_title:s.role_title.trim()||null,email:s.email.trim()||null,phone:s.phone.trim()||null,dni:s.dni.trim()||null,birth_date:s.birth_date||null,address:s.address.trim()||null,iban:s.iban.trim()||null,contract_type:s.contract_type.trim()||null,contract_start:s.contract_start||null,contract_end:s.contract_end||null,salary:j,salary_period:s.salary_period.trim()||null,conditions:s.conditions.trim()||null,notes:s.notes.trim()||null};if(_(!0),r){const{error:b}=await v.from("employees").update(g).eq("id",r.id);if(_(!1),b){x.error("No se pudo guardar",{description:b.message});return}x.success("Cambios guardados"),M({detail:`employees:update:${r.id}:${a}`})}else{const{data:b}=await v.auth.getSession(),L=b.session?.user.id??null,{data:S,error:D}=await v.from("employees").insert({...g,created_by:L}).select("id").single();if(_(!1),D){x.error("No se pudo crear",{description:D.message});return}x.success(`${a} añadido`),M({detail:`employees:create:${S?.id??""}:${a}`})}h(!1)}return e.jsx(Q,{open:t,onOpenChange:h,children:e.jsxs(X,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Y,{children:[e.jsx(K,{children:r?"Editar persona":"Añadir persona"}),e.jsx(W,{children:"Todos los campos son opcionales salvo el nombre. Puedes escribir lo que quieras en notas y condiciones."})]}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx(A,{children:"Datos básicos"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx(i,{label:"CategorÃa",children:e.jsxs($,{value:s.category,onValueChange:a=>n("category",a),children:[e.jsx(q,{children:e.jsx(I,{})}),e.jsx(F,{children:E.map(a=>e.jsx(w,{value:a.key,children:a.label},a.key))})]})}),e.jsx(i,{label:"Nombre completo *",children:e.jsx(u,{value:s.full_name,onChange:a=>n("full_name",a.target.value),maxLength:200,placeholder:"Nombre y apellidos"})}),e.jsx(i,{label:"Rol / puesto",children:e.jsx(u,{value:s.role_title,onChange:a=>n("role_title",a.target.value),maxLength:200,placeholder:"Ej: Base, Entrenadora principal, Presidenteâ¦"})}),e.jsx(i,{label:"DNI / NIE",children:e.jsx(u,{value:s.dni,onChange:a=>n("dni",a.target.value),maxLength:30})}),e.jsx(i,{label:"Fecha de nacimiento",children:e.jsx(u,{type:"date",value:s.birth_date,onChange:a=>n("birth_date",a.target.value)})}),e.jsx(i,{label:"Dirección",full:!0,children:e.jsx(u,{value:s.address,onChange:a=>n("address",a.target.value),maxLength:300})})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx(A,{children:"Contacto"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx(i,{label:"Email",children:e.jsx(u,{type:"email",value:s.email,onChange:a=>n("email",a.target.value),maxLength:255})}),e.jsx(i,{label:"Teléfono",children:e.jsx(u,{value:s.phone,onChange:a=>n("phone",a.target.value),maxLength:40})}),e.jsx(i,{label:"IBAN",full:!0,children:e.jsx(u,{value:s.iban,onChange:a=>n("iban",a.target.value),maxLength:40,placeholder:"ES.."})})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx(A,{children:"Contrato y s
1alario"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx(i,{label:"Tipo de contrato",children:e.jsx(u,{value:s.contract_type,onChange:a=>n("contract_type",a.target.value),maxLength:100,placeholder:"Ej: Indefinido, temporal, becariaâ¦"})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(i,{label:"Inicio",children:e.jsx(u,{type:"date",value:s.contract_start,onChange:a=>n("contract_start",a.target.value)})}),e.jsx(i,{label:"Fin",children:e.jsx(u,{type:"date",value:s.contract_end,onChange:a=>n("contract_end",a.target.value)})})]}),e.jsx(i,{label:"Salario (â¬)",children:e.jsx(u,{inputMode:"decimal",value:s.salary,onChange:a=>n("salary",a.target.value),placeholder:"0,00"})}),e.jsx(i,{label:"Periodo",children:e.jsxs($,{value:s.salary_period,onValueChange:a=>n("salary_period",a),children:[e.jsx(q,{children:e.jsx(I,{})}),e.jsxs(F,{children:[e.jsx(w,{value:"mensual",children:"Mensual"}),e.jsx(w,{value:"anual",children:"Anual"}),e.jsx(w,{value:"por hora",children:"Por hora"}),e.jsx(w,{value:"por partido",children:"Por partido"}),e.jsx(w,{value:"voluntario",children:"Voluntario"})]})]})}),e.jsx(i,{label:"Condiciones",full:!0,children:e.jsx(B,{value:s.conditions,onChange:a=>n("conditions",a.target.value),maxLength:2e3,rows:3,placeholder:"Bonus, dietas, dÃas libresâ¦"})})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx(A,{children:"Notas libres"}),e.jsx(B,{value:s.notes,onChange:a=>n("notes",a.target.value),maxLength:5e3,rows:4,placeholder:"Escribe cualquier cosa que quieras recordar sobre esta personaâ¦"})]})]}),e.jsxs(Z,{children:[e.jsx(T,{variant:"outline",onClick:()=>h(!1),disabled:m,children:"Cancelar"}),e.jsxs(T,{onClick:k,disabled:m,children:[m?e.jsx(G,{className:"h-4 w-4 mr-1 animate-spin"}):null,r?"Guardar cambios":"Crear"]})]})]})})}function A({children:t}){return e.jsx("h3",{className:"text-sm font-bold uppercase tracking-wide text-muted-foreground border-b pb-1",children:t})}function i({label:t,children:r,full:h}){return e.jsxs("div",{className:N("space-y-1",h&&"sm:col-span-2"),children:[e.jsx(J,{className:"text-xs",children:t}),r]})}export{oa as component};
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.