1import{f as ie,bs as ne,u as le,r as d,s as m,j as e,h as b,i as N,k,l as C,m as E,e as _,B as g,X as oe,I as U,L as ce,A as de,g as l}from"./index-DLd_kDlx.js";import{L as y}from"./label-D4-ENrYn.js";import{T as me}from"./textarea-C6X-I43k.js";import{u as ue,U as z}from"./url-input-Dei4E79g.js";import{a as F,e as B,c as xe}from"./AssessmentUI-DW2eB-aa.js";import{U as q}from"./upload-CCEcMTV9.js";import{L as pe}from"./loader-circle-D2miE2xB.js";import{P as he}from"./plus-0WhrdjYO.js";import{A as fe}from"./arrow-left-BXtn7MCa.js";import{S as ge}from"./save-DnzFMk1L.js";import"./linkValidation-XNJaCD7E.js";import"./external-link-D0CFvOTk.js";function Ve(){const{user:u}=ie(),{assessmentStatus:o,createAssessment:Y,updateAssessmentStage:H}=ne(),O=le(),{validateUrl:V}=ue(),[i,x]=d.useState({githubUrl:"",linkedinUrl:"",workExperiences:[]}),[t,G]=d.useState(null),[v,J]=d.useState(null),[X,$]=d.useState(""),[K,p]=d.useState(!1),[D,P]=d.useState(!1),[j,S]=d.useState(!1),[L,h]=d.useState("");d.useEffect(()=>{M()},[o==null?void 0:o.id]);const M=async()=>{if(o!=null&&o.id)try{const{data:s,error:r}=await m.from("xtern_assessment_experience").select("*").eq("assessment_id",o.id).maybeSingle();if(r)throw r;if(s&&(x({githubUrl:s.github_url||"",linkedinUrl:s.linkedin_url||"",workExperiences:s.work_experiences||[]}),s.cv_file_id)){J(s.cv_file_id);const{data:a,error:n}=await m.from("cv_files").select("filename").eq("id",s.cv_file_id).single();a&&!n&&$(a.filename)}}catch(s){console.error("Error loading existing data:",s)}},Q=()=>{const s={id:Date.now().toString(),company:"",role:"",duration:"",description:""};x(r=>({...r,workExperiences:[...r.workExperiences,s]}))},Z=s=>{x(r=>({...r,workExperiences:r.workExperiences.filter(a=>a.id!==s)}))},w=(s,r,a)=>{x(n=>({...n,workExperiences:n.workExperiences.map(c=>c.id===s?{...c,[r]:a}:c)}))},ee=async s=>{var a;const r=(a=s.target.files)==null?void 0:a[0];r&&(r.type==="application/pdf"||r.type.startsWith("image/")?(G(r),$(r.name),await se(r)):l.error("Please upload a PDF or image file"))},se=async s=>{if(u){S(!0),h("Uploading CV...");try{const r=`${u.id}_${Date.now()}_${s.name}`,a=`${u.id}/${r}`,{error:n}=await m.storage.from("cv-files").upload(a,s);if(n)throw n;const{data:c,error:I}=await m.from("cv_files").insert({user_id:u.id,filename:s.name,file_path:a,content_type:s.type,file_size:s.size}).select().single();if(I)throw I;h("Extracting text...");const{data:te,error:R}=await m.functions.invoke("extract-cv-text",{body:{cvFileId:c.id}});if(R)throw R;h("Analyzing experience...");const{data:f,error:T}=await m.functions.invoke("parse-work-experience",{body:{extractedText:te.extractedText,cvFileId:c.id}});if(T)throw T;h("Complete!"),f.workExperiences&&f.workExperiences.length>0?(x(W=>({...W,workExperiences:[...W.workExperiences,...f.workExperiences]})),l.success(`Extracted ${f.count} work experience${f.count!==1?"s":""} from your CV!`)):l.info("No work experience found in CV. You can add them manually."),setTimeout(()=>{h("")},1500)}catch(r){console.error("Error extracting work experience:",r),l.error("Failed to extract work experience from CV. You can add them manually.")}finally{S(!1)}}},re=async()=>{if(!t||!u)return null;try{const s=`${u.id}_${Date.now()}_${t.name}`,r=`${u.id}/${s}`,{error:a}=await m.storage.from("cv-files").upload(r,t);if(a)throw a;const{data:n,error:c}=await m.from("cv_files").insert({user_id:u.id,filename:t.name,file_path:r,content_type:t.type,file_size:t.size}).select().single();if(c)throw c;return n.id}catch(s){return console.error("Error uploading CV:",s),l.error("Failed to upload CV"),null}},A=async()=>{let s=o==null?void 0:o.id;if(!s){const r=await Y();if(!r)return;s=r.id}P(!0);try{let r=v;if(t){const n=await re();n&&(r=n)}const{error:a}=await m.from("xtern_assessment_experience").upsert({assessment_id:s,github_url:i.githubUrl||null,linkedin_url:i.linkedinUrl||null,work_experiences:i.workExperiences,cv_file_id:r},{onConflict:"assessment_id"});if(a)throw a;l.success("Progress saved successfully")}catch(r){console.error("Error saving data:",r),l.error("Failed to save progress")}finally{P(!1)}},ae=async()=>
1{if(!t&&!v){l.error("CV upload is required. Please upload your CV to continue with your assessment.");return}if(i.githubUrl||i.linkedinUrl){p(!0);try{if(i.githubUrl){const s=await V(i.githubUrl,"github");if(s.status==="invalid"||s.status==="error"){l.error(s.message||"Please enter a valid GitHub profile URL or leave the field empty."),p(!1);return}}if(i.linkedinUrl){const s=await V(i.linkedinUrl,"linkedin");if(s.status==="invalid"||s.status==="error"){l.error(s.message||"Please enter a valid LinkedIn profile URL or leave the field empty."),p(!1);return}}}catch(s){console.error("Error validating URLs:",s),l.error("Unable to validate profile URLs. Please check your internet connection."),p(!1);return}}p(!0);try{await A(),await H(1,!0),O("/assessment/stage-2")}catch(s){console.error("Error continuing:",s),l.error("Failed to continue")}finally{p(!1)}};return e.jsx("div",{className:"min-h-screen bg-gray-50 px-4 py-8 font-sans text-gray-950 sm:px-6 sm:py-12",children:e.jsxs("div",{className:"mx-auto max-w-3xl",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"mb-2 font-display text-3xl font-normal tracking-tight text-xterns-navy sm:text-4xl",children:"Stage 1: Experience"}),e.jsx("p",{className:"text-base text-gray-500",children:"Tell us about your professional background and experience"})]}),e.jsxs("div",{className:"mb-8",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Stage 1 of 3"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"33% Complete"})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-gray-200/70",children:e.jsx("div",{className:"h-2 w-1/3 rounded-full bg-gradient-to-r from-xterns-blue to-xterns-teal transition-all duration-300"})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(b,{className:F,children:[e.jsxs(N,{children:[e.jsxs(k,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"w-5 h-5"}),"Upload CV",e.jsx("span",{className:"ml-2 text-sm font-normal text-destructive",children:"*Required"})]}),e.jsx(C,{children:"Upload your CV to complete your assessment. PDF or image files supported - work experience will be auto-extracted."})]}),e.jsx(E,{children:e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-6 text-center transition-all duration-300 ${j?"border-primary bg-primary/5":"border-muted-foreground/25"}`,children:[e.jsx("input",{type:"file",accept:".pdf,image/*",onChange:ee,className:"hidden",id:"cv-upload",disabled:j}),e.jsx("label",{htmlFor:"cv-upload",className:`cursor-pointer ${j?"pointer-events-none":""}`,children:j?e.jsxs("div",{className:"animate-fade-in",children:[e.jsx(pe,{className:"w-8 h-8 mx-auto mb-3 text-primary animate-spin"}),e.jsx("p",{className:"text-base font-medium text-primary mb-2",children:L}),e.jsx("div",{className:"flex justify-center mb-2",children:e.jsxs("div",{className:"flex space-x-1",children:[e.jsx("div",{className:"w-2 h-2 bg-primary rounded-full animate-pulse"}),e.jsx("div",{className:"w-2 h-2 bg-primary rounded-full animate-pulse",style:{animationDelay:"0.1s"}}),e.jsx("div",{className:"w-2 h-2 bg-primary rounded-full animate-pulse",style:{animationDelay:"0.2s"}})]})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait while we analyze your CV"})]}):L==="Complete!"?e.jsxs("div",{className:"animate-fade-in",children:[e.jsx(_,{className:"w-8 h-8 mx-auto mb-2 text-green-600"}),e.jsx("p",{className:"text-base font-medium text-green-700 mb-1",children:"Extraction Complete!"})]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:t?t.name:"Click to upload your CV"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"PDF or image files supported - work experience will be auto-extracted"})]})})]})})]}),v&&!t&&e.jsxs("div",{className:"p-4 bg-success/10 border border-success/20 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-success",children:[e.jsx(_,{className:"w-5 h-5"}),e.jsxs("span",{className:"font-medium",children:["CV Already Uploaded: ",X||"Previous CV"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 ml-7",children:"You can upload a new file to replace your existing CV"})]}),t&&e.jsxs("div",{className:"p-4 bg-primary/10 border border-primary/20 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary",children:[e.jsx(_,{className:"w-5 h-5"}),e.jsxs("span",{className:"font-medium",children:["New CV Selected: ",t.name]})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 ml-7",children:v?"This will replace your previous CV when you continue":"Work experience will be auto-extracted"})]}),e.jsxs(b,{className:F,children:[e.jsxs(N,{children:[e.jsx(k,{children:"Work Experience (Optional)"}),e.jsx(C,{children:"Add your relevant work experiences or upload a CV to auto-extract them"})]}),e.jsxs(E,{className:"space-y-4",children:[i.workExperiences.map((s,r)=>e.jsxs("div",{className:"border rounded-lg p-4 relative",children:[e.jsx(g,{variant:"ghost",size:"sm",className:"absolute top-2 right-2",onClick:()=>Z(s.id),children:e.jsx(oe,{className:"w-4 h-4"})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx(y,{htmlFor:`company-${s.id}`,children:"Company"}),e.jsx(U,{id:`company-${s.id}`,value:s.company,onChange:a=>w(s.id,"company",a.target.value),placeholder:"Company name"})]}),e.jsxs("div",{children:[e.jsx(y,{htmlFor:`role-${s.id}`,children:"Role"}),e.jsx(U,{id:`role-${s.id}`,value:s.role,onChange:a=>w(s.id,"role",a.target.value),placeholder:"Your role"})]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx(y,{htmlFor:`duration-${s.id}`,children:"Duration"}),e.jsx(U,{id:`duration-${s.id}`,value:s.duration,onChange:a=>w(s.id,"duration",a.target.value),placeholder:"e.g., Jan 2022 - Present"})]}),e.jsxs("div",{children:[e.jsx(y,{htmlFor:`description-${s.id}`,children:"Description"}),e.jsx(me,{id:`description-${s.id}`,value:s.description,onChange:a=>w(s.id,"description",a.target.value),placeholder:"Describe your responsibilities and achievements",rows:3})]})]},s.id)),e.jsxs(g,{variant:"outline",onClick:Q,className:"w-full",children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),"Add Work Experience"]})]})]}),e.jsxs(b,{className:F,children:[e.jsxs(N,{children:[e.jsx(k,{children:"Professional Links (Optional)"}),e.jsx(C,{children:"Add your professional social media profiles"})]}),e.jsxs(E,{className:"space-y-4",children:[e.jsx(z,{id:"github",label:"GitHub URL",value:i.githubUrl,onChange:s=>x(r=>({...r,githubUrl:s})),placeholder:"https://github.com/yourusername",type:"github"}),e.jsx(z,{id:"linkedin",label:"LinkedIn URL",value:i.linkedinUrl,onChange:s=>x(r=>({...r,linkedinUrl:s})),placeholder:"https://linkedin.com/in/yourprofile",type:"linkedin"})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-3 pt-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(g,{variant:"outline",className:B,asChild:!0,children:e.jsxs(ce,{to:"/assessment",children:[e.jsx(fe,{className:"w-4 h-4 mr-2"}),"Back"]})}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs(g,{variant:"outline",className:B,onClick:A,disabled:D,children:[e.jsx(ge,{className:"w-4 h-4 mr-2"}),D?"Saving...":"Save Progress"]}),e.jsxs(g,{className:xe,onClick:ae,disabled:K,children:["Continue",e.jsx(de,{className:"w-4 h-4 ml-2"})]})]})]})]})]})})}export{Ve as default};
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.