var __gh = require("react").createElement, __gf = require("react").Fragment; var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var stdin_exports={};__export(stdin_exports,{default:()=>stdin_default,featureConfig:()=>featureConfig});module.exports=__toCommonJS(stdin_exports);var dataSources=[];var import_react=require("react"),COMPANY_ID=640,API_BASE=typeof window<"u"&&window.location.hostname==="localhost"?"http://localhost:3000":"",INK="#0a2540",INK_2="#27405a",MUTED="#425466",FAINT="#657387",HAIRLINE="#e3e8ee",CANVAS="#f6f9fc",ACCENT="#635bff",ACCENT_DEEP="#4d44e0",MAL="#ff3b30",OK="#34c759",FUENTE='-apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif',SOMBRA="0 0 0 0.5px rgba(10,37,64,0.045), 0 1px 1px rgba(10,37,64,0.028), 0 3px 8px -2px rgba(10,37,64,0.035)";async function llamar(name,body){let res=await fetch(`${API_BASE}/api/public/${COMPANY_ID}/automation/${name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}),json=await res.json().catch(()=>({}));if(!res.ok){let e=new Error(json?.error||"No se ha podido conectar");throw e.status=res.status,e}return json&&json.success===!0&&"result"in json?json.result:json}var CAMPOS=[{clave:"dni_nie",etiqueta:"DNI o NIE",placeholder:"12345678Z",tipo:"texto",autoComplete:"off"},{clave:"nss",etiqueta:"N\xFAmero de la Seguridad Social",ayuda:"Son 11 o 12 cifras. Viene en cualquier n\xF3mina anterior, o se pide en Import@ss.",placeholder:"281234567890",tipo:"texto",inputMode:"numeric"},{clave:"iban",etiqueta:"IBAN donde cobrar",placeholder:"ES00 0000 0000 0000 0000 0000",tipo:"texto",autoComplete:"off"},{clave:"fecha_nacimiento",etiqueta:"Fecha de nacimiento",tipo:"fecha",autoComplete:"bday"},{clave:"telefono",etiqueta:"Tel\xE9fono",placeholder:"612 345 678",tipo:"texto",inputMode:"tel",autoComplete:"tel"},{clave:"direccion",etiqueta:"Domicilio",ayuda:"Calle, n\xFAmero, piso, c\xF3digo postal y municipio.",tipo:"texto",autoComplete:"street-address"},{clave:"sexo",etiqueta:"Sexo",ayuda:"S\xF3lo se usa para el registro retributivo que exige el RD 902/2020. \xABPrefiero no decirlo\xBB tambi\xE9n vale.",tipo:"sexo"}];function fechaBonita(v){if(!v)return"";let d=new Date(v);return Number.isNaN(d.getTime())?"":new Intl.DateTimeFormat("es-ES",{day:"numeric",month:"long",year:"numeric",timeZone:"Europe/Madrid"}).format(d)}function PortalDeAlta({id}){let[fase,setFase]=(0,import_react.useState)("cargando"),[v,setV]=(0,import_react.useState)(null),[valores,setValores]=(0,import_react.useState)({}),[errores,setErrores]=(0,import_react.useState)({}),[general,setGeneral]=(0,import_react.useState)(""),[enviando,setEnviando]=(0,import_react.useState)(!1),[guardados,setGuardados]=(0,import_react.useState)([]),token=(0,import_react.useMemo)(()=>{if(typeof window>"u")return"";let q=new URLSearchParams(window.location.search);return(q.get("t")||q.get("token")||"").trim()},[]);(0,import_react.useEffect)(()=>{if(!token){setFase("sin_enlace");return}let vivo=!0;return(async()=>{try{let r=await llamar("rrhh_alta_verify",{token});if(!vivo)return;if(!r||r.ok!==!0){setFase(r&&r.reason==="proceso_cerrado"?"cerrado":"invalido");return}setV(r),setFase(r.falta.length===0?"hecho":"form")}catch{vivo&&(setGeneral("No se ha podido comprobar el enlace. Revisa la conexi\xF3n y recarga."),setFase("invalido"))}})(),()=>{vivo=!1}},[token]);let pendientes=(0,import_react.useMemo)(()=>CAMPOS.filter(c=>v?.falta.includes(c.clave)),[v]),enviar=async()=>{if(!v||enviando)return;let datos={};for(let c of pendientes){let val=(valores[c.clave]||"").trim();val&&(datos[c.clave]=val)}if(Object.keys(datos).length===0){setGeneral("Rellena al menos un dato antes de guardar.");return}setEnviando(!0),setErrores({}),setGeneral("");try{let r=await llamar("rrhh_alta_submit",{token,datos});if(r&&r.ok===!0)setGuardados(r.guardados||[]),(r.falta||[]).length===0?setFase("hecho"):(setV({...v,falta:r.falta}),setValores({}),setGeneral("Guardado. Queda lo de abajo \u2014 este mismo enlace sigue valiendo si lo quieres dejar para luego."));else if(r&&r.reason==="datos_no_validos"){let porCampo={};for(let e of r.errores||[])porCampo[e.campo]=e.motivo;setErrores(porCampo),setGeneral("Hay datos que no cuadran. Est\xE1n marcados abajo.")}else setGeneral("El enlace ya no vale. Pide uno nuevo a quien te lo mand\xF3.")}catch{setGeneral("No se ha podido guardar. Revisa la conexi\xF3n y vuelve a intentarlo.")}finally{setEnviando(!1)}};return __gh("div",{id,style:{minHeight:"100vh",background:CANVAS,color:INK,fontFamily:FUENTE,WebkitFontSmoothing:"antialiased",display:"flex",flexDirection:"column",alignItems:"center",padding:"0 16px"},"data-gufi-src":"page.tsx:171"},__gh("main",{style:{width:"100%",maxWidth:560,padding:"48px 0 64px"},"data-gufi-src":"page.tsx:176"},fase==="cargando"?__gh("p",{style:{textAlign:"center",color:MUTED,fontSize:14},"data-gufi-src":"page.tsx:178"},"Comprobando el enlace\u2026"):null,fase==="sin_enlace"||fase==="invalido"?__gh(Cabecera,{titulo:"Este enlace no es v\xE1lido"},__gh("p",{style:estiloParrafo,"data-gufi-src":"page.tsx:183"},general||"O est\xE1 incompleto, o ya no existe. Pide a quien te lo mand\xF3 que te lo genere de nuevo.")):null,fase==="cerrado"?__gh(Cabecera,{titulo:"Este enlace ya se ha cerrado"},__gh("p",{style:estiloParrafo,"data-gufi-src":"page.tsx:191"},"El proceso de incorporaci\xF3n al que pertenec\xEDa est\xE1 cerrado. Si te falta algo por entregar, habla directamente con la empresa.")):null,fase==="form"&&v?__gh(__gf,null,__gh(Cabecera,{antetitulo:v.empresa,titulo:v.nombre?`Hola, ${v.nombre}`:"Hola"},__gh("p",{style:estiloParrafo,"data-gufi-src":"page.tsx:204"},v.fecha_incorporacion?`Tu incorporaci\xF3n es el ${fechaBonita(v.fecha_incorporacion)}. `:"","Antes del primer d\xEDa hacen falta estos datos para tu alta y tu n\xF3mina. Son dos minutos y s\xF3lo se piden una vez.")),general?__gh("p",{role:"alert",style:{margin:"0 0 16px",padding:"12px 16px",borderRadius:10,fontSize:13.5,lineHeight:1.5,background:"#fff",border:`1px solid ${HAIRLINE}`,boxShadow:SOMBRA,color:INK_2},"data-gufi-src":"page.tsx:214"},general):null,__gh("form",{onSubmit:e=>{e.preventDefault(),enviar()},style:{background:"#fff",borderRadius:14,boxShadow:SOMBRA,padding:"8px 20px 20px",display:"flex",flexDirection:"column"},"data-gufi-src":"page.tsx:223"},pendientes.map(c=>__gh(Campo,{key:c.clave,def:c,valor:valores[c.clave]||"",error:errores[c.clave],onCambio:val=>setValores(p=>({...p,[c.clave]:val}))})),__gh("button",{type:"submit",disabled:enviando,style:{marginTop:20,padding:"14px 24px",borderRadius:10,border:"none",backgroundImage:`linear-gradient(180deg, ${ACCENT} 0%, ${ACCENT_DEEP} 100%)`,color:"#fff",fontSize:16,fontWeight:600,fontFamily:FUENTE,cursor:enviando?"default":"pointer",opacity:enviando?.6:1,boxShadow:"0 1px 2px rgba(10,37,64,0.08), 0 2px 6px -1px rgba(99,91,255,0.22)"},"data-gufi-src":"page.tsx:239"},enviando?"Guardando\u2026":"Guardar mis datos")),__gh("p",{style:{margin:"18px 4px 0",fontSize:12,color:FAINT,lineHeight:1.55},"data-gufi-src":"page.tsx:254"},"Estos datos van directos a tu ficha de empleado en ",v.empresa,", se usan s\xF3lo para la relaci\xF3n laboral (alta, contrato y n\xF3mina) y los tratar\xE1 la empresa conforme al RGPD. Podr\xE1s ejercer tus derechos de acceso y rectificaci\xF3n con ella.")):null,fase==="hecho"&&v?__gh(Cabecera,{antetitulo:v.empresa,titulo:v.nombre?`Todo listo, ${v.nombre}`:"Todo listo"},__gh("div",{style:{display:"flex",justifyContent:"center",margin:"4px 0 14px"},"data-gufi-src":"page.tsx:264"},__gh("span",{"aria-hidden":!0,style:{width:56,height:56,borderRadius:999,background:"#fff",boxShadow:SOMBRA,display:"inline-flex",alignItems:"center",justifyContent:"center"},"data-gufi-src":"page.tsx:265"},__gh("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,"data-gufi-src":"page.tsx:269"},__gh("path",{d:"M5 12.5 10 17.5 19 7",stroke:OK,strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","data-gufi-src":"page.tsx:270"})))),__gh("p",{style:estiloParrafo,"data-gufi-src":"page.tsx:274"},guardados.length>0?"Datos guardados. ":"","Tu ficha est\xE1 completa y no hace falta nada m\xE1s por aqu\xED.",v.fecha_incorporacion?` Nos vemos el ${fechaBonita(v.fecha_incorporacion)}.`:"")):null))}var estiloParrafo={margin:0,fontSize:15,lineHeight:1.55,color:MUTED,textAlign:"center"};function Cabecera({antetitulo,titulo,children}){return __gh("header",{style:{textAlign:"center",marginBottom:24},"data-gufi-src":"page.tsx:296"},antetitulo?__gh("span",{style:{display:"block",fontSize:12.5,fontWeight:600,color:MUTED,letterSpacing:"0.01em",marginBottom:10},"data-gufi-src":"page.tsx:298"},antetitulo):null,__gh("h1",{style:{margin:"0 0 10px",fontSize:"clamp(26px, 6vw, 34px)",fontWeight:600,letterSpacing:"-0.02em",lineHeight:1.1,color:INK},"data-gufi-src":"page.tsx:305"},titulo),children)}function Campo({def,valor,error,onCambio}){let idCampo=`alta-${def.clave}`,base={width:"100%",boxSizing:"border-box",padding:"12px 14px",fontSize:16,fontFamily:FUENTE,color:INK,background:"#fff",border:`1px solid ${error?MAL:HAIRLINE}`,borderRadius:10,outline:"none"};return __gh("div",{style:{paddingTop:16},"data-gufi-src":"page.tsx:323"},__gh("label",{htmlFor:idCampo,style:{display:"block",fontSize:13,fontWeight:600,color:INK_2,marginBottom:6},"data-gufi-src":"page.tsx:324"},def.etiqueta),def.tipo==="sexo"?__gh("div",{role:"radiogroup","aria-label":def.etiqueta,style:{display:"flex",gap:8,flexWrap:"wrap"},"data-gufi-src":"page.tsx:328"},[{v:"mujer",t:"Mujer"},{v:"hombre",t:"Hombre"},{v:"no_consta",t:"Prefiero no decirlo"}].map(o=>{let activo=valor===o.v;return __gh("button",{key:o.v,type:"button",role:"radio","aria-checked":activo,onClick:()=>onCambio(activo?"":o.v),style:{padding:"10px 16px",borderRadius:999,fontSize:14,fontFamily:FUENTE,fontWeight:activo?600:500,cursor:"pointer",background:activo?"#fff":"rgba(66,84,102,0.07)",color:activo?INK:MUTED,border:activo?`1.5px solid ${ACCENT}`:"1.5px solid transparent",boxShadow:activo?SOMBRA:"none"},"data-gufi-src":"page.tsx:336"},o.t)})):def.tipo==="fecha"?__gh("input",{id:idCampo,type:"date",value:valor,max:new Date(Date.now()-14*365.25*864e5).toISOString().slice(0,10),min:"1900-01-01",onChange:e=>onCambio(e.target.value),"aria-invalid":!!error,autoComplete:def.autoComplete,style:base,"data-gufi-src":"page.tsx:357"}):__gh("input",{id:idCampo,type:"text",value:valor,placeholder:def.placeholder,inputMode:def.inputMode,autoComplete:def.autoComplete,onChange:e=>onCambio(e.target.value),"aria-invalid":!!error,style:base,"data-gufi-src":"page.tsx:367"}),error?__gh("span",{role:"alert",style:{display:"block",fontSize:12.5,color:"#c4291f",marginTop:5,lineHeight:1.4},"data-gufi-src":"page.tsx:378"},error):def.ayuda?__gh("span",{style:{display:"block",fontSize:12.5,color:FAINT,marginTop:5,lineHeight:1.45},"data-gufi-src":"page.tsx:382"},def.ayuda):null)}var featureConfig={dataSources,meta:{name:"Portal de alta",version:"1.0.0"}};var stdin_default=PortalDeAlta;