import{j as e,a as u}from"./api.QF7ase0K.js";import{r as n}from"./index.DC1_V0l1.js";import{R as p}from"./tipos.BUIEL7Hd.js";const g={admin:"badge badge-info",lider:"badge badge-warning",colaborador:"badge badge-success",consultor:"badge badge-gray"};function j({perfiles:c,onSeleccionado:d,onCerrar:a}){const[t,o]=n.useState(null),[i,l]=n.useState("");async function m(r){o(r.id),l("");try{const s=await u.post("/auth/seleccionar-perfil",{perfil_id:r.id});localStorage.setItem("crew_token",s.access_token);const x=JSON.parse(localStorage.getItem("crew_usuario")||"{}");localStorage.setItem("crew_usuario",JSON.stringify({...x,rol:s.perfil.rol,empresa_id:s.perfil.empresa_id,perfil_id:s.perfil.id,empresa_nombre:s.perfil.empresa_nombre})),d?.(),window.location.href="/dashboard"}catch(s){l(s instanceof Error?s.message:"Error al seleccionar perfil"),o(null)}}return e.jsx("div",{className:"fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-2xl w-full max-w-md",children:[e.jsxs("div",{className:"flex items-start justify-between p-6 border-b border-gray-100",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:"Selecciona tu perfil"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Tienes acceso a múltiples empresas. ¿Con cuál deseas continuar?"})]}),a&&e.jsx("button",{onClick:a,className:"p-2 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-lg transition-colors -mt-1 -mr-1",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),i&&e.jsx("div",{className:"mx-6 mt-4 p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:i}),e.jsx("div",{className:"p-4 space-y-2",children:c.map(r=>e.jsxs("button",{onClick:()=>m(r),disabled:t!==null,className:"w-full flex items-center justify-between p-4 rounded-xl border border-gray-200 hover:border-navy hover:bg-navy/5 transition-all text-left disabled:opacity-60 disabled:cursor-not-allowed group",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-gray-900 group-hover:text-navy",children:r.empresa_nombre}),e.jsx("span",{className:`${g[r.rol]} mt-1 inline-block`,children:p[r.rol]})]}),t===r.id?e.jsxs("svg",{className:"w-5 h-5 text-navy animate-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):e.jsx("svg",{className:"w-5 h-5 text-gray-300 group-hover:text-navy transition-colors",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},r.id))})]})})}export{j as S};
