module.exports=[73840,a=>{"use strict";let b=(0,a.i(45618).createClient)("https://ixrgjfluwrwkzpxoaocw.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Iml4cmdqZmx1d3J3a3pweG9hb2N3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQ3MjY3MTQsImV4cCI6MjA5MDMwMjcxNH0.XpWgQTUidHKlXUWRDnkpx6-ouhBvPArcpV-wDqEyuwg");a.s(["supabase",0,b])},61989,a=>{"use strict";var b=a.i(37936),c=a.i(73840),d=a.i(18558),e=a.i(45618),f=a.i(13095);let g=(0,e.createClient)("https://ixrgjfluwrwkzpxoaocw.supabase.co",process.env.SUPABASE_SERVICE_ROLE_KEY,{auth:{autoRefreshToken:!1,persistSession:!1}});async function h(a){if(!a)return null;let b=a.trim().toLowerCase(),c=1;for(;;){let{data:a,error:d}=await g.auth.admin.listUsers({page:c,perPage:100});if(d||!a||!a.users||0===a.users.length)break;let e=a.users.find(a=>a.email?.toLowerCase()===b);if(e)return e.id;if(a.users.length<100)break;c++}return null}async function i(a,b){try{let{data:d,error:e}=await c.supabase.from("leads").select("id, nombre, correo, telefono, status").or(`correo.ilike.${a},telefono.ilike.${b}`);if(e)return console.error("Error checking lead duplicate:",e),{error:e.message};return{duplicates:d||[]}}catch(a){return{error:a.message}}}async function j(a){try{let{error:b}=await g.from("leads").insert([{...a,status:a.status||"Nuevo",source:a.source||"manual"}]);if(b)return console.error("Error creating manual lead:",b),{success:!1,error:b.message};return(0,d.revalidatePath)("/gestion-corpadein/crm"),{success:!0}}catch(a){return{success:!1,error:a.message}}}async function k(){try{let{data:a,error:b}=await c.supabase.from("programs").select("id, title").order("title");if(b)throw b;return a||[]}catch(a){return console.error("Error fetching programs:",a),[]}}async function l(a,b){try{if("Candidato"===b)return await n(a);if("Estudiante"===b)return await m(a);let{error:c}=await g.from("leads").update({status:b}).eq("id",a);if(c)return console.error("Error updating lead status:",c),{success:!1,error:c.message};return(0,d.revalidatePath)("/gestion-corpadein/crm"),{success:!0}}catch(a){return{success:!1,error:a.message}}}async function m(a){try{let b,{data:c,error:e}=await g.from("leads").select("*").eq("id",a).single();if(e||!c)throw Error("No se pudo obtener el lead: "+e?.message);let f=Math.random().toString(36).slice(-10)+"C1!";if(!(b=await h(c.correo)||void 0)){let{data:a,error:d}=await g.auth.admin.createUser({email:c.correo,password:f,email_confirm:!0});if(d)if(d.message.toLowerCase().includes("already registered")){if(!(b=await h(c.correo)||void 0))throw Error("El usuario ya existe pero no se pudo recuperar su ID de Auth.")}else throw Error("Error creando usuario Auth: "+d.message);else b=a?.user?.id}if(!b)throw Error("No se pudo determinar el ID de usuario para el perfil.");let{error:i}=await g.from("profiles").upsert({id:b,role:"estudiante",nombre:c.nombre,correo:c.correo});if(i)throw Error("Error al crear perfil de estudiante: "+i.message);return await g.from("leads").update({status:"Estudiante"}).eq("id",a),console.log(`[SIMULACI\xd3N EMAIL] Enviado a: ${c.correo}`),console.log(`Asunto: \xa1Bienvenido a Corpadein!`),console.log(`Mensaje: Tu cuenta de estudiante ha sido creada. Accede con ${c.correo} / clave: ${f}`),(0,d.revalidatePath)("/gestion-corpadein/crm"),{success:!0,message:`Usuario convertido a estudiante con \xe9xito. Si ya ten\xeda cuenta, su perfil ha sido actualizado.`}}catch(a){return console.error("Error en convertLeadToStudent:",a),{success:!1,error:a.message}}}async function n(a){try{let b,{data:c,error:e}=await g.from("leads").select("*").eq("id",a).single();if(e||!c)throw Error("No se pudo obtener el lead: "+e?.message);let f=Math.random().toString(36).slice(-10)+"C1!";if(!(b=await h(c.correo)||void 0)){let{data:a,error:d}=await g.auth.admin.createUser({email:c.correo,password:f,email_confirm:!0});if(d)if(d.message.toLowerCase().includes("already registered")){if(!(b=await h(c.correo)||void 0))throw Error("El usuario ya existe pero no se pudo recuperar su ID de Auth.")}else throw Error("Error creando usuario Auth: "+d.message);else b=a?.user?.id}if(!b)throw Error("No se pudo determinar el ID de usuario para el perfil.");let{error:i}=await g.from("profiles").upsert({id:b,role:"candidato",nombre:c.nombre,correo:c.correo});if(i)throw Error("Error al crear perfil de candidato: "+i.message);return await g.from("leads").update({status:"Candidato"}).eq("id",a),console.log(`[SIMULACI\xd3N EMAIL] Enviado a: ${c.correo}`),console.log(`Asunto: Documentaci\xf3n de Inscripci\xf3n Corpadein`),console.log(`Mensaje: Tu cuenta ha sido activada para cargar tus documentos. Accede con ${c.correo} / clave: ${f}`),(0,d.revalidatePath)("/gestion-corpadein/crm"),{success:!0,message:`Email: ${c.correo}
Contrase\xf1a Temporal: ${f}`}}catch(a){return console.error("Error en convertLeadToInterested:",a),{success:!1,error:a.message}}}async function o(){let{data:a}=await g.from("profiles").select("id, nombre").in("role",["admin","comercial","tecnologia","contabilidad","academia","admin_crm"]).order("nombre");return a||[]}async function p(a,b){let{error:c}=await g.from("leads").update({assigned_to:b}).eq("id",a);return c?{success:!1,error:c.message}:((0,d.revalidatePath)("/gestion-corpadein/crm"),{success:!0})}async function q(a){let{data:b}=await g.from("lead_comments").select("*, profiles(nombre, role)").eq("lead_id",a).order("created_at",{ascending:!1});return b||[]}async function r(a,b,c){let{error:d}=await g.from("lead_comments").insert({lead_id:a,author_id:b,content:c});return d?{success:!1,error:d.message}:{success:!0}}async function s(a,b,c){return b?r(a,b,c):{success:!1,error:"No author ID provided"}}async function t(a,b){try{let c={};["nombre","correo","telefono","nivel","programa_id","ciudad","status","assigned_to","source","city","level_interest"].forEach(a=>{void 0!==b[a]&&(c[a]=b[a])}),"Inscrito"===c.status&&(c.status="Estudiante");let{error:e}=await g.from("leads").update(c).eq("id",a);if(e)return console.error("Error updating lead:",e),{success:!1,error:e.message};return(0,d.revalidatePath)("/gestion-corpadein/crm"),{success:!0}}catch(a){return{success:!1,error:a.message}}}(0,f.ensureServerEntryExports)([i,j,k,l,m,n,o,p,q,r,s,t]),(0,b.registerServerReference)(i,"605b52256f63190b4f24fece360753382468a614bb",null),(0,b.registerServerReference)(j,"4063bf292bd7bcf8e63b6bab55cbeff515e71eac66",null),(0,b.registerServerReference)(k,"00fbe1b1b154c31fe0e8cb559d604a49b37f6d318f",null),(0,b.registerServerReference)(l,"60f55b7442aac54a717d94f4f2d5324d08f439443a",null),(0,b.registerServerReference)(m,"407e1af7ca92c7b61a4996a7a7b9ec1c7e68d87544",null),(0,b.registerServerReference)(n,"404c909ebd3b905a12844d27b00acbb97c93e4cf0c",null),(0,b.registerServerReference)(o,"006c4d93f453ae58d87fae9d2d377041e12b486253",null),(0,b.registerServerReference)(p,"60f2586c40fbc9015dcdb23bb74f23d7aff75ca17e",null),(0,b.registerServerReference)(q,"40a4e8d46c4a0f0ba92b661ca993361cabad77834c",null),(0,b.registerServerReference)(r,"70703e80fd8bd0b4e13795dfce5f5a6abbbe646127",null),(0,b.registerServerReference)(s,"70fe97088fc05d6af379519579153a801f103e7823",null),(0,b.registerServerReference)(t,"6088f408a2161292c66fff716b870ecafcefc48241",null),a.s(["addLeadCommentAction",()=>s,"assignLeadTo",()=>p,"checkLeadDuplicate",()=>i,"convertLeadToInterested",()=>n,"convertLeadToStudent",()=>m,"createManualLead",()=>j,"getComerciales",()=>o,"getLeadComments",()=>q,"getPrograms",()=>k,"moveLeadStatus",()=>l,"updateLead",()=>t])},46728,a=>{"use strict";var b=a.i(54143),c=a.i(61989);a.s([],7485),a.i(7485),a.s(["00fbe1b1b154c31fe0e8cb559d604a49b37f6d318f",()=>c.getPrograms,"4063bf292bd7bcf8e63b6bab55cbeff515e71eac66",()=>c.createManualLead,"408752d41840a9129533a279989e29f571a78e21c2",()=>b.getSiteSettings,"605b52256f63190b4f24fece360753382468a614bb",()=>c.checkLeadDuplicate],46728)}];

//# sourceMappingURL=_d60157df._.js.map