import{j as e}from"./vendor-radix-DNp60FuA.js";import{r as p,f as ve,j as je,L as I}from"./vendor-react-DL0tRKZA.js";import{u as ee,s as b,t as z,r as de,p as Ne,S as we,v as _e,N as B,B as G,U as ke,c as Fe,w as Ce,x as Se,k as M,y as Le,z as Pe}from"./index-DyYtMrmN.js";import{a as Ae,b as qe}from"./vendor-query-CKQAY9LX.js";import{a as Re}from"./useJobs-BjPEwLd7.js";import{u as ce,a as Ie}from"./useResumeUploads-ClUGvp9V.js";import{u as Ve}from"./useProfileMutations-D9Ct4MGh.js";import{C as De}from"./country-select-DYhLO0Rx.js";import{t as K}from"./th-generated-icon-CcDaMvWl.js";import{H}from"./HeroSection-ScWndVAI.js";import{A as Ee,a as ze}from"./alert-CMw4tQSV.js";import O from"./Footer-DRUZJt2_.js";import{C as me}from"./circle-check-big-CnxgyMMZ.js";import{F as X}from"./file-text-C0SFgrpd.js";import{S as Te}from"./send-B3b7Jsik.js";import{B as Z}from"./brain-D6EzJYto.js";import{I as T}from"./info-BcGo3pkx.js";import"./vendor-supabase-B4f4CcZD.js";import"./vendor-charts-CPng-d0O.js";import"./supabase-queries-3k0wiR_7.js";import"./command-BrJR7h3G.js";import"./search-C1f5IQll.js";import"./popover-Cou35VfA.js";import"./countries-jDUnRHCO.js";import"./scroll-area-Dgnneqa-.js";import"./chevrons-up-down-K3h8FrvN.js";import"./check-DILptOyH.js";import"./BreadcrumbWrapper-BvjYrzZr.js";import"./chevron-right-BRHR7U8q.js";import"./index-CBP-sTs2.js";import"./index-2qSVHfop.js";import"./use-mobile-DG-UVPpq.js";import"./handshake-Bbai7pkW.js";import"./cpu-DQQ2pOpR.js";const Ue=()=>{const r=Ae(),{user:t}=ee();return{applyForJob:qe({mutationFn:async a=>{var h,x,c;if(!(t!=null&&t.id))throw new Error("Please sign in to apply for jobs");const{data:d,error:v}=await b.from("jobs").select("id, is_active, application_deadline, max_applications, total_applications").eq("id",a.jobId).eq("is_active",!0).eq("approval_status","approved").single();if(v||!d)throw new Error("Job not found or no longer accepting applications");if(d.application_deadline){const i=new Date(d.application_deadline);if(i.setHours(23,59,59,999),i<new Date)throw new Error("The application deadline for this job has passed")}if(d.max_applications&&d.total_applications>=d.max_applications)throw new Error("This job has reached the maximum number of applications");const{data:f,error:k}=await b.from("job_applications").select("id, status").eq("job_id",a.jobId).eq("applicant_id",t.id).maybeSingle();if(k)throw console.error("Error checking for duplicate application:",k),new Error("Unable to verify application status. Please try again.");if(f)throw new Error(`You have already applied for this job (Status: ${f.status})`);let g=null,F=null;if(a.resumeFile&&!a.useExistingResume){if(!["application/pdf"].includes(a.resumeFile.type))throw new Error("Please upload a PDF document for your resume");const s=5*1024*1024;if(a.resumeFile.size>s)throw new Error("Resume file size must be less than 5MB");const m=a.resumeFile.name.split(".").pop(),u=`${t.id}/${Date.now()}.${m}`,{error:N}=await b.storage.from("resumes").upload(u,a.resumeFile,{cacheControl:"3600",upsert:!1,contentType:"application/pdf"});if(N){console.error("Resume upload error:",N);const w=navigator.userAgent||"",C=/Android|iPhone|iPad|iPod/i.test(w);throw new Error(C?"We're aware of an issue with CV uploads on mobile devices. Please try uploading your CV from a desktop computer for the best experience.":"Failed to upload resume. Please try again.")}if(g=u,a.saveToLibrary!==!1){console.log("📄 Creating resume_uploads entry for reuse...");try{const{data:w}=await b.from("resume_uploads").select("id").eq("user_id",t.id).eq("is_current",!0).maybeSingle(),{data:C,error:P}=await b.from("resume_uploads").insert({user_id:t.id,file_name:a.resumeFile.name,file_size:a.resumeFile.size,file_type:a.resumeFile.type,storage_path:u,is_current:!w,upload_status:"uploaded",analysis_status:"pending",upload_date:new Date().toISOString()}).select().single();P?console.warn("⚠️ Failed to create resume_uploads entry:",P):(console.log("✅ Resume saved to resume_uploads for future use:",C.id),F=C.id)}catch(w){console.warn("⚠️ Resume upload entry creation error (non-blocking):",w)}}else console.log("📭 User chose not to save resume to library (one-time use only)")}else if(a.useExistingResume&&a.selectedResumeId){const{data:i,error:s}=await b.from("resume_uploads").select("storage_path, id").eq("id",a.selectedResumeId).eq("user_id",t.id).single();if(s||!i)throw new Error("Selected resume not found. Please select a different resume.");g=i.storage_path,F=i.id}else if(a.useExistingResume&&!a.selectedResumeId){const{data:i,error:s}=await b.from("profiles").select("resume_url").eq("id",t.id).single();if(s)throw new Error("Unable to access your profile. Please try again.");if(!(i!=null&&i.resume_url))throw new Error("No resume found. Please select a resume or upload a new one.");g=i.resume_url}if(!g)throw new Error("A resume is required to apply for this job");const j={job_id:a.jobId,applicant_id:t.id,cover_letter:((h=a.coverLetter)==null?void 0:h.trim())||null,resume_url:g,status:"pending"},{data:l,error:o}=await b.from("job_applications").insert(j).select(`
*,
job:jobs(title, posted_by, company:companies(name))
`).single();if(o)throw console.error("Application creation error:",o),new Error("Failed to submit application. Please try again.");if(l&&g)try{console.log(`🎯 [APPLY] Starting application submission for job: ${a.jobId}`),console.log(`👤 [APPLY] Applicant ID: ${l.id}`),console.log(`📄 [APPLY] Resume URL: ${g}`),console.log("⏭️ [APPLY] Queueing CV analyses (job-specific + standalone)...");const{data:i}=await b.from("cv_analysis_queue").select("id, status").eq("application_id",l.id).in("status",["pending","processing"]).maybeSingle();if(i)console.log("⏭️ [APPLY] CV analysis already queued/processing, skipping queue insertion"),console.log("📊 [APPLY] Existing job:",i);else{console.log("➕ [APPLY] Queueing job-specific CV analysis...");const{error:s,data:m}=await b.from("cv_analysis_queue").insert({application_id:l.id,job_id:a.jobId,resume_url:g,resume_upload_id:F,status:"pending",retry_count:0,max_retries:3}).select().single();if(s)throw console.error("❌ [APPLY] Failed to queue job-specific CV analysis:",s),new Error(`CV analysis queue error: ${s.message}`);console.log("✅ [APPLY] Job-specific CV analysis queued:",m)}F?(console.log("📊 Queueing standalone CV analysis for resume:",F),Promise.resolve(b.functions.invoke("standalone-cv-analysis",{body:{resumeUrl:g,resumeUploadId:F}})).then(({data:s,error:m})=>{if(m){console.warn("⚠️ Standalone CV analysis failed (non-blocking):",m);return}return console.log("✅ Standalone CV analysis initiated:",s),b.from("resume_uploads").update({analysis_status:"completed"}).eq("id",F)}).then(s=>{s&&console.log("✅ Resume analysis status updated")}).catch(async s=>{var N,w;(s==null?void 0:s.name)==="FunctionsFetchError"||((N=s==null?void 0:s.message)==null?void 0:N.includes("Failed to send"))?console.log("⏭️ CV analysis deferred to background queue (mobile network):",(s==null?void 0:s.message)||"request cancelled"):console.warn("⚠️ Background standalone analysis error (non-critical):",(s==null?void 0:s.message)||s);let u=null;try{(w=s==null?void 0:s.context)!=null&&w.body&&(u=typeof s.context.body=="string"?JSON.parse(s.context.body):s.context.body)}catch{console.warn("Could not parse standalone analysis error details")}if((u==null?void 0:u.errorCategory)==="name_validation_failed"){const{extractedName:C,expectedName:P}=u.details||{};z({title:"CV Name Doesn't Match Profile",description:C&&P?`Your CV shows "${C}" but your profile name is "${P}". Please update your profile or upload the correct CV.`:"The name on your CV doesn't match your profile. Please check your profile settings or upload a CV with your correct name.",variant:"destructive",duration:1e4})}else u!=null&&u.error&&z({title:"CV Analysis Delayed",description:u.error||"Your resume was saved but analysis will be completed in the background.",variant:"default",duration:5e3})}),console.log("✅ Standalone CV analysis queued in background")):a.saveToLibrary===!1&&console.log("📭 Skipping standalone CV analysis (resume not saved to library)"),console.log("✅ CV analysis processing setup complete")}catch(i){console.error("❌ [APPLY] CV analysis queueing failed:",i)}try{console.log("📧 [APPLY] Notifying employer of new application..."),Promise.resolve(b.functions.invoke("notify-employer-new-application",{body:{application_id:l.id,job_id:a.jobId,job_title:((x=l.job)==null?void 0:x.title)||"position",employer_id:(c=l.job)==null?void 0:c.posted_by,candidate_id:t.id,created_at:l.applied_at}})).then(({error:i})=>{i?console.warn("⚠️ Employer notification failed (non-blocking):",i):console.log("✅ Employer notification sent successfully")}).catch(i=>{console.warn("⚠️ Background employer notification error (non-critical):",i)})}catch(i){console.warn("⚠️ Failed to trigger employer notification:",i)}try{const{data:i}=await b.from("job_bookmarks").select("id").eq("user_id",t.id).eq("job_id",a.jobId).maybeSingle();if(!i){const{error:s}=await b.from("job_bookmarks").insert({user_id:t.id,job_id:a.jobId});s?console.warn("Failed to auto-bookmark job:",s):console.log("Job automatically bookmarked after application")}}catch(i){console.warn("Error during auto-bookmark:",i)}return l},onSuccess:a=>{var d;r.invalidateQueries({queryKey:["candidate-applications",t==null?void 0:t.id]}),r.invalidateQueries({queryKey:["candidate-bookmarks",t==null?void 0:t.id]}),r.invalidateQueries({queryKey:["candidate-stats",t==null?void 0:t.id]}),r.invalidateQueries({queryKey:["job-application-status",t==null?void 0:t.id]}),r.invalidateQueries({queryKey:["employerApplications"]}),r.invalidateQueries({queryKey:["employerApplicationStats"]}),r.invalidateQueries({queryKey:["jobStats"]}),r.invalidateQueries({queryKey:["jobs"]}),r.invalidateQueries({queryKey:["job",a.job_id]}),r.invalidateQueries({queryKey:["resume-uploads",t==null?void 0:t.id]}),r.invalidateQueries({queryKey:["current-resume",t==null?void 0:t.id]}),r.invalidateQueries({queryKey:["all-standalone-cv-analyses",t==null?void 0:t.id]}),z({title:"Application Submitted Successfully!",description:`Your application for ${(d=a.job)==null?void 0:d.title} has been submitted. We'll analyze your CV and notify you of any updates.`})},onError:a=>{console.error("Error applying for job:",a),z({variant:"destructive",title:"Application Failed",description:a.message||"Failed to submit application. Please try again."})}})}},Je=()=>{const{user:r}=ee(),{data:t}=de(),{data:_}=ce(),{data:a}=Ie(),[d,v]=p.useState({fullName:"",email:"",phone:"",location:"",country:"",coverLetter:"",selectedResumeId:""}),[f,k]=p.useState({resume:{selected:"",source:"none",available:!1},profile:{filled:!1,source:"none"},coverLetter:{source:"none",isGenerating:!1},rankedResumes:[],recommendedResumeId:""});return p.useEffect(()=>{if(!r)return;const l=t?`${t.first_name||""} ${t.last_name||""}`.trim():"",o={fullName:l,email:r.email||(t==null?void 0:t.email)||"",phone:(t==null?void 0:t.phone)||"",location:(t==null?void 0:t.location)||"",country:(t==null?void 0:t.country)||""};let h="none";t!=null&&t.bio&&t.bio.trim()&&(o.coverLetter=t.bio,h="bio");let x={selected:"",source:"none",available:!1},c=[],i="";_&&_.length>0&&(c=_.map(s=>{let m=0;const u=[];s.is_current&&(m+=50,u.push("current"));const N=Math.floor((Date.now()-new Date(s.created_at).getTime())/(1e3*60*60*24));return N<=30?m+=30:N<=90&&(m+=15),s.analysis_status==="completed"&&(m+=20,u.push("ai-scored")),{id:s.id,fileName:s.file_name,score:m,isCurrent:s.is_current,uploadDate:s.created_at,aiScore:void 0,badges:u}}).sort((s,m)=>m.score-s.score),c.length>0&&(c[0].badges.unshift("recommended"),i=c[0].id,x={selected:c[0].id,source:c[0].isCurrent?"current":"latest",available:!0},o.selectedResumeId=c[0].id)),v(s=>({...s,...o})),k({resume:x,profile:{filled:!!(l||r.email||t!=null&&t.email||t!=null&&t.phone||t!=null&&t.location),source:"profile"},coverLetter:{source:h,isGenerating:!1},rankedResumes:c,recommendedResumeId:i})},[r,t,_,a]),{autoFillData:d,autoFillSource:f,updateAutoFillData:l=>{v(o=>({...o,...l}))},resetAutoFill:()=>{v({fullName:"",email:"",phone:"",location:"",country:"",coverLetter:"",selectedResumeId:""})},generateCoverLetter:async l=>{if(!(!t||!l)){k(o=>({...o,coverLetter:{source:o.coverLetter.source,isGenerating:!0}}));try{const{data:{session:o}}=await b.auth.getSession();if(!(o!=null&&o.access_token))throw new Error("No active session");const{data:h,error:x}=await b.functions.invoke("generate-cover-letter",{headers:{Authorization:`Bearer ${o.access_token}`},body:{jobId:l,candidateProfile:{fullName:`${t.first_name||""} ${t.last_name||""}`.trim(),email:t.email||(r==null?void 0:r.email),bio:t.bio,location:t.location}}});if(x)throw x;if(h!=null&&h.coverLetter)v(c=>({...c,coverLetter:h.coverLetter})),k(c=>({...c,coverLetter:{source:"ai-generated",isGenerating:!1}}));else if(h!=null&&h.fallback){const c=(t==null?void 0:t.bio)||"";v(i=>({...i,coverLetter:c})),k(i=>({...i,coverLetter:{source:"bio",isGenerating:!1}}))}}catch(o){console.error("Error generating cover letter:",o);const h=(t==null?void 0:t.bio)||"";v(x=>({...x,coverLetter:h})),k(x=>({...x,coverLetter:{source:"bio",isGenerating:!1}}))}}},isLoading:!t&&!!r}},W=[{id:1,label:"Validating application",icon:me},{id:2,label:"Processing resume",icon:X},{id:3,label:"Creating application",icon:Te},{id:4,label:"Analyzing your CV",icon:Z},{id:5,label:"Finalizing",icon:we}],$e=({currentStage:r=1,message:t})=>{var _,a;return(_=W[r-1])!=null&&_.icon||me,e.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-50 flex items-center justify-center animate-fade-in",children:e.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-8 max-w-md w-full mx-4 shadow-2xl animate-scale-in",children:[e.jsx("h3",{className:"text-lg font-semibold text-center mb-4 text-foreground",children:(a=W[r-1])==null?void 0:a.label}),e.jsx("div",{className:"flex justify-center gap-2 mb-4",children:W.map(d=>e.jsx("div",{className:Ne("h-2 w-12 rounded-full transition-all duration-500 ease-out",d.id<r&&"bg-emerald-600",d.id===r&&"bg-emerald-600 animate-pulse",d.id>r&&"bg-muted")},d.id))}),t&&e.jsx("p",{className:"text-sm text-muted-foreground text-center animate-fade-in",children:t})]})})};function kt(){var oe,le,ne;const{user:r}=ee(),t=ve(),[_]=je(),a=_.get("jobId"),{data:d,isLoading:v}=de(),{data:f,isLoading:k,error:g}=Re(a||""),{applyForJob:F}=Ue(),{toast:j}=_e(),{autoFillData:l,autoFillSource:o,updateAutoFillData:h,generateCoverLetter:x,isLoading:c}=Je(),[i,s]=p.useState(""),[m,u]=p.useState(""),[N,w]=p.useState(""),[C,P]=p.useState(""),[U,te]=p.useState(""),[J,se]=p.useState(""),[S,$]=p.useState(null),[L,V]=p.useState(""),[Y,ue]=p.useState(!0),[ae,pe]=p.useState(!1),[ie,D]=p.useState(!1),[Q,re]=p.useState(!1),[fe,q]=p.useState(0),[be,R]=p.useState(""),{data:E,isLoading:Ye}=ce(),he=Ve();p.useEffect(()=>{l&&!c&&(s(l.fullName),u(l.email||(r==null?void 0:r.email)||""),w(l.phone),P(l.location),te(l.country),se(l.coverLetter),!ae&&!ie&&!S&&l.selectedResumeId&&(V(l.selectedResumeId),pe(!0)))},[l,c,r==null?void 0:r.email,S,ae,ie]),p.useEffect(()=>{a&&d&&!c&&o.coverLetter.source!=="ai-generated"&&!o.coverLetter.isGenerating&&x(a)},[a,d,c]);const xe=n=>{te(n),r&&d&&!d.country&&he.mutate({userId:r.id,data:{country:n}})},ge=async n=>{var A;if(n.preventDefault(),!r){j({title:"Sign In Required",description:"Please sign in to apply for jobs",variant:"destructive"});return}if(!a){j({title:"Job Not Found",description:"Please select a job to apply for.",variant:"destructive"});return}if(f.application_deadline){const y=new Date(f.application_deadline);if(y.setHours(23,59,59,999),y<new Date){j({title:"Application Deadline Passed",description:"Sorry, the application deadline for this job has passed.",variant:"destructive"});return}}if(!i.trim()||!m.trim()){j({title:"Missing Information",description:"Please provide your full name and email address.",variant:"destructive"});return}if(!U.trim()){j({title:"Country Required",description:"Please select your country to continue.",variant:"destructive"});return}if(!L&&!S){j({title:"Resume Required",description:"Please select a resume or upload a new one.",variant:"destructive"});return}re(!0),q(1),R("Validating your application...");try{q(2),R(S?"Uploading your resume...":"Selecting your resume..."),await new Promise(y=>setTimeout(y,400)),q(3),R("Submitting your application..."),await F.mutateAsync({jobId:a,coverLetter:J.trim()||void 0,resumeFile:S||void 0,selectedResumeId:L||void 0,useExistingResume:!!L&&!S,saveToLibrary:S?Y:void 0,applicantName:i.trim()||void 0,applicantEmail:m.trim()||void 0,applicantPhone:N.trim()||void 0,applicantLocation:U||C.trim()||void 0}),q(4),R("Analyzing your CV with AI..."),await new Promise(y=>setTimeout(y,600)),q(5),R("Almost done..."),await new Promise(y=>setTimeout(y,400)),t("/job-application-success",{state:{jobTitle:f.title,companyName:(A=f.company)==null?void 0:A.name}})}catch{}finally{re(!1),q(0),R("")}},ye=n=>{var y;const A=(y=n.target.files)==null?void 0:y[0];if(A){if(D(!0),!["application/pdf"].includes(A.type)){j({title:"Invalid File Type",description:"Please upload a PDF document",variant:"destructive"});return}if(A.size>5*1024*1024){j({title:"File Too Large",description:"File size must be less than 5MB",variant:"destructive"});return}$(A),V("")}};return k||v?e.jsxs(e.Fragment,{children:[e.jsx(B,{navClass:"!justify-end nav-light"}),e.jsx(H,{title:"Apply for Job",description:"Loading job details...",breadcrumbItems:[{label:"Home",href:"/"},{label:"Jobs",href:"/job-list"},{label:"Apply",isActive:!0}],variant:"emerald"}),e.jsx("section",{className:"relative bg-slate-50 dark:bg-slate-800 py-16",children:e.jsx("div",{className:"container",children:e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-emerald-600"})})})}),e.jsx(O,{})]}):!a||g||!f?e.jsxs(e.Fragment,{children:[e.jsx(B,{navClass:"!justify-end nav-light"}),e.jsx(H,{title:"Job Not Found",description:"The job you're trying to apply for doesn't exist or is no longer available.",breadcrumbItems:[{label:"Home",href:"/"},{label:"Jobs",href:"/job-list"},{label:"Apply",isActive:!0}],variant:"emerald"}),e.jsx("section",{className:"relative bg-slate-50 dark:bg-slate-800 py-16",children:e.jsx("div",{className:"container",children:e.jsx("div",{className:"flex justify-center",children:e.jsx(I,{to:"/job-list",className:"py-2 px-5 inline-block font-semibold tracking-wide border align-middle transition duration-500 ease-in-out text-base text-center rounded-md bg-emerald-600 hover:bg-emerald-700 border-emerald-600 hover:border-emerald-700 text-white",children:"Browse Available Jobs"})})})}),e.jsx(O,{})]}):e.jsxs(e.Fragment,{children:[e.jsx(B,{navClass:"!justify-end nav-light"}),e.jsx(H,{title:`Apply for ${f.title}`,description:`at ${(oe=f.company)==null?void 0:oe.name}`,breadcrumbItems:[{label:"Home",href:"/"},{label:"Jobs",href:"/job-list"},{label:f.title,href:`/job-detail-one/${f.id}`},{label:"Apply",isActive:!0}],variant:"emerald"}),e.jsx("section",{className:"relative bg-slate-50 dark:bg-slate-800 lg:py-24 py-16",children:e.jsx("div",{className:"container",children:e.jsx("div",{className:"md:flex justify-center",children:e.jsx("div",{className:"lg:w-5/6 md:w-11/12",children:e.jsx("div",{className:"p-6 bg-white dark:bg-slate-900 shadow-sm shadow-gray-200 dark:shadow-gray-700 rounded-md",children:r?v?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-emerald-600"}),e.jsx("span",{className:"ml-3",children:"Loading your profile..."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ee,{className:"mb-6",children:[e.jsx(T,{className:"h-4 w-4"}),e.jsx(ze,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:["Applying for: ",e.jsx("strong",{children:f.title})," at ",e.jsx("strong",{children:(le=f.company)==null?void 0:le.name})]}),e.jsx(I,{to:`/job-detail-one/${f.id}`,className:"text-primary hover:underline text-sm",children:"View Job Details"})]})})]}),d&&o.profile.filled&&e.jsxs("div",{className:"mb-6 p-4 bg-gradient-to-r from-emerald-50 to-blue-50 dark:from-emerald-900/20 dark:to-blue-900/20 rounded-lg border border-emerald-200 dark:border-emerald-700",children:[e.jsx("div",{className:"flex items-start gap-3",children:e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("img",{src:K,alt:"",className:"h-4 w-4 text-emerald-600"}),e.jsx("span",{className:"text-sm font-medium text-emerald-700 dark:text-emerald-300",children:"Smart Auto-Fill Applied"})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-3 w-3 text-emerald-600"}),e.jsx("span",{className:"text-emerald-700 dark:text-emerald-300",children:"Profile data auto-filled"})]}),o.resume.available&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-3 w-3 text-orange-600"}),e.jsxs("span",{className:"text-slate-700 dark:text-slate-300",children:[o.resume.source==="current"?"Current":"Latest"," resume selected"]})]})]}),e.jsx("div",{className:"mt-3 pt-3 border-t border-emerald-200 dark:border-emerald-700",children:e.jsxs(I,{to:"/candidate/settings",className:"text-xs text-emerald-600 hover:text-emerald-700 hover:underline flex items-center gap-1",children:[e.jsx(T,{className:"h-3 w-3"}),"Update your profile to improve auto-fill accuracy"]})})]}),e.jsx("form",{className:"text-left",onSubmit:ge,children:e.jsxs("div",{className:"grid grid-cols-1",children:[e.jsxs("div",{className:"mb-5 ltr:text-left rtl:text-right",children:[e.jsx("label",{className:"font-semibold",htmlFor:"RegisterName",children:"Your Name: *"}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(Fe,{className:"absolute top-1/2 -translate-y-1/2 start-4 size-4 text-slate-400 z-20 pointer-events-none"}),e.jsx("input",{id:"RegisterName",type:"text",className:"form-input border border-slate-100 dark:border-slate-800 w-full !ps-11 h-12",placeholder:"Your full name",value:i,onChange:n=>s(n.target.value),required:!0})]})]}),e.jsxs("div",{className:"mb-5 ltr:text-left rtl:text-right",children:[e.jsx("label",{className:"font-semibold",htmlFor:"LoginEmail",children:"Email Address: *"}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(Ce,{className:"absolute top-1/2 -translate-y-1/2 start-4 size-4 text-slate-400 z-20 pointer-events-none"}),e.jsx("input",{id:"LoginEmail",type:"email",className:"form-input border border-slate-100 dark:border-slate-800 w-full !ps-11 h-12",placeholder:"name@example.com",value:m,onChange:n=>u(n.target.value),required:!0})]})]}),e.jsxs("div",{className:"mb-5 ltr:text-left rtl:text-right",children:[e.jsx("label",{className:"font-semibold",htmlFor:"PhoneNo",children:"Phone No.:"}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(Se,{className:"absolute top-1/2 -translate-y-1/2 start-4 size-4 text-slate-400 z-20 pointer-events-none"}),e.jsx("input",{id:"PhoneNo",type:"tel",className:"form-input border border-slate-100 dark:border-slate-800 w-full !ps-11 h-12",placeholder:"+1 (555) 123-4567",value:N,onChange:n=>w(n.target.value)})]})]}),e.jsxs("div",{className:"mb-5 ltr:text-left rtl:text-right",children:[e.jsx("label",{className:"font-semibold",children:"Country *"}),e.jsx("div",{className:"relative mt-2",children:e.jsx(De,{value:U,onValueChange:xe,placeholder:"Select your country (required)"})})]}),e.jsxs("div",{className:"mb-5 ltr:text-left rtl:text-right",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("label",{htmlFor:"comments",className:"font-semibold flex items-center gap-2",children:["Cover Letter:",o.coverLetter.source==="ai-generated"&&e.jsxs(M,{variant:"secondary",className:"text-xs",children:[e.jsx("img",{src:K,alt:"",className:"w-4 h-4 mr-1"}),"TH Generated"]})]}),a&&!o.coverLetter.isGenerating&&e.jsxs(G,{type:"button",variant:"ghost",size:"sm",onClick:()=>x(a),className:"text-xs",children:[e.jsx(Z,{className:"h-3 w-3 mr-1"}),o.coverLetter.source==="ai-generated"?"Regenerate":"Generate with AI"]})]}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(Le,{className:"absolute top-4 start-4 size-4 text-slate-400 z-20 pointer-events-none"}),e.jsx("textarea",{name:"comments",id:"comments",className:"form-input border border-slate-100 dark:border-slate-800 textarea w-full !ps-11 h-28 py-3",placeholder:o.coverLetter.isGenerating?"AI is generating your cover letter...":"Write your cover letter here...",value:J,onChange:n=>se(n.target.value),disabled:o.coverLetter.isGenerating}),o.coverLetter.isGenerating&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 backdrop-blur-sm rounded-md animate-fade-in",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5 text-primary animate-pulse"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Generating personalized cover letter"}),e.jsxs("span",{className:"flex gap-0.5",children:[e.jsx("span",{className:"animate-[bounce_1s_ease-in-out_0s_infinite]",children:"."}),e.jsx("span",{className:"animate-[bounce_1s_ease-in-out_0.2s_infinite]",children:"."}),e.jsx("span",{className:"animate-[bounce_1s_ease-in-out_0.4s_infinite]",children:"."})]})]})]}),e.jsx("div",{className:"w-48 h-1 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary rounded-full animate-[shimmer_1.5s_ease-in-out_infinite]",style:{width:"40%"}})})]})})]}),(d==null?void 0:d.bio)&&J===d.bio&&o.coverLetter.source==="bio"&&e.jsxs("p",{className:"text-xs text-slate-500 mt-1 flex items-center gap-1 ml-11",children:[e.jsx(T,{className:"h-3 w-3"}),"Pre-filled with your profile bio"]}),o.coverLetter.source==="ai-generated"&&e.jsxs("p",{className:"text-xs text-emerald-600 dark:text-emerald-400 mt-1 flex items-center gap-1 ml-11",children:[e.jsx("img",{src:K,alt:"",className:"h-3 w-3"}),"This cover letter was personalized for this position using AI"]})]}),e.jsxs("div",{className:"mb-5 ltr:text-left rtl:text-right",children:[e.jsx("label",{className:"font-semibold mb-3 block",children:"Resume Selection:"}),o.resume.available&&e.jsx("div",{className:"mb-3 p-3 bg-gradient-to-r from-green-50 to-emerald-50 dark:from-green-900/20 dark:to-emerald-900/20 rounded-md border border-green-200 dark:border-green-700",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(X,{className:"h-4 w-4 text-green-600"}),e.jsx("span",{className:"text-green-700 dark:text-green-300 font-medium",children:o.resume.source==="current"?"Current resume auto-selected":"Latest resume auto-selected"}),e.jsx(M,{variant:"outline",className:"text-xs border-green-300 text-green-700",children:"Smart pick"})]})}),E&&E.length>0&&e.jsxs("div",{className:"mb-4 p-4 bg-slate-50 dark:bg-slate-800 rounded-md",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("input",{type:"radio",id:"use-uploaded-resume",name:"resume-option",checked:!!L,onChange:()=>{D(!0),$(null)},className:"h-4 w-4"}),e.jsx("label",{htmlFor:"use-uploaded-resume",className:"text-sm font-medium",children:"Select from your uploaded resumes"}),o.resume.available&&e.jsx(M,{variant:"secondary",className:"text-xs",children:o.resume.source==="current"?"Current selected":"Latest selected"})]}),e.jsxs("div",{className:"ml-6",children:[e.jsxs("select",{className:"form-select form-input border border-slate-100 dark:border-slate-800 block w-full h-10 text-sm",value:L,onChange:n=>{D(!0),V(n.target.value),$(null)},children:[e.jsx("option",{value:"",children:"Choose a resume..."}),E.map(n=>e.jsxs("option",{value:n.id,children:[n.file_name,n.is_current&&" (Current)",n.upload_date&&` - ${new Date(n.upload_date).toLocaleDateString()}`]},n.id))]}),L&&e.jsxs("p",{className:"text-xs text-slate-500 mt-1 flex items-center gap-1",children:[e.jsx(T,{className:"h-3 w-3"}),(ne=E.find(n=>n.id===L))!=null&&ne.is_current?"This is your current resume":"Preview and verify this resume before applying"]})]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("input",{type:"radio",id:"new-resume",name:"resume-option",checked:!L,onChange:()=>{D(!0),V("")},className:"h-4 w-4"}),e.jsx("label",{className:"text-sm font-medium",htmlFor:"new-resume",children:"Upload a new resume"})]}),!L&&e.jsxs("div",{className:"ml-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Pe,{className:"absolute top-1/2 -translate-y-1/2 start-4 size-4 text-slate-400 z-20 pointer-events-none"}),e.jsx("input",{className:"form-input border border-slate-100 dark:border-slate-800 file:h-10 file:-mx-3 file:-my-2 file:cursor-pointer file:rounded-none file:border-0 file:px-3 file:text-neutral-700 bg-clip-padding px-3 py-3 file:me-3 w-full !ps-11 h-12",id:"resume_file",type:"file",accept:".pdf",onChange:ye})]}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"Supported: PDF only (Max 5MB)"}),S&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-emerald-600 mt-1",children:["Selected: ",S.name]}),e.jsx("div",{className:"mt-3 p-3 bg-blue-50 dark:bg-blue-900/20 rounded-md border border-blue-200 dark:border-blue-700",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("input",{type:"checkbox",id:"saveResume",checked:Y,onChange:n=>ue(n.target.checked),className:"mt-0.5 h-4 w-4 text-emerald-600 rounded"}),e.jsxs("label",{htmlFor:"saveResume",className:"text-sm text-slate-700 dark:text-slate-300 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:"Save this resume to my library"}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1",children:Y?"✓ You'll be able to reuse this resume for future applications and get standalone CV analysis":"This resume will only be used for this application"})]})]})})]})]})]})]}),e.jsx("div",{children:e.jsx("button",{type:"submit",disabled:Q||!i.trim()||!m.trim(),className:"py-2 px-6 inline-block font-semibold tracking-wide border align-middle transition duration-500 ease-in-out text-base text-center rounded-md bg-emerald-600 hover:bg-emerald-700 border-emerald-600 hover:border-emerald-700 text-white w-full disabled:opacity-50 disabled:cursor-not-allowed",children:Q?"Submitting Application...":"Apply Now"})})]})})]}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Sign In Required"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"You need to sign in to apply for jobs."}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx(G,{asChild:!0,children:e.jsx(I,{to:"/auth/login",children:"Sign In"})}),e.jsx(G,{variant:"outline",asChild:!0,children:e.jsx(I,{to:"/",children:"Go Home"})})]})]})})})})})}),e.jsx(O,{}),Q&&e.jsx($e,{currentStage:fe,message:be})]})}export{kt as default};