1import{r as f,E as S,s as v,j as e,B as j,b as $,a as M,X as Z,I as P,Z as H,f as O,aK as V,bt as L,bu as F,aZ as W,h as N,m as b,a7 as ee,J as se,i as k,k as E,p as te,aL as ae,aa as re,ab as ie,ac as ne}from"./index-DLd_kDlx.js";import{u as le}from"./useXternCVData-DVgkff8K.js";import{P as oe}from"./PublicCVLayout-BhhwDZLk.js";import{R as q}from"./refresh-cw-CoPjtj5-.js";import{S as A}from"./switch-7Twrb7Os.js";import{L as _}from"./label-D4-ENrYn.js";import{T as ce}from"./textarea-C6X-I43k.js";import{P as de}from"./pencil-CYx02MS_.js";import{P as I}from"./plus-0WhrdjYO.js";import{T as me}from"./trash-2-0uuZSTFd.js";import{S as xe}from"./save-DnzFMk1L.js";import{L as pe}from"./loader-circle-D2miE2xB.js";import{S as R}from"./share-C1adk9AK.js";import{D as ue}from"./download-Cr0jatld.js";import{S as he}from"./star-BH1OFEcs.js";import{E as fe}from"./eye-CRDofLPH.js";import{I as je}from"./info-BLiu1f4f.js";import{C as ge}from"./copy-B3ncjnG6.js";import{L as ve}from"./link-_ZZxygmy.js";import"./useEIScore-C48npH32.js";import"./format-BTXglRCX.js";import"./en-US-9SRVm7yB.js";import"./proxy-D0Q57V63.js";import"./badge-check-BG9dn4bq.js";import"./map-pin-ChCNbN_o.js";import"./mail-BVn2o8AP.js";import"./linkedin-C3YpjTq8.js";import"./globe-C057RQ73.js";import"./share-2-BPEjAYf2.js";import"./shield-check-C7sUiJPm.js";import"./trending-up-BU4cR3Ys.js";import"./trophy-DBX-jNOC.js";import"./briefcase-business-CphIeAJd.js";import"./link-2-DxGcptQD.js";const ye=()=>{const[t,d]=f.useState(!1),{toast:o}=S();return{syncPersonalExperience:async m=>{var r;d(!0);try{const{data:i,error:l}=await v.from("cv_files").select("id, extracted_text, file_path").eq("user_id",m).order("uploaded_at",{ascending:!1}).limit(1).maybeSingle();if(l)throw l;if(!i)return o({title:"No CV found",description:"Please upload a CV during onboarding to sync personal experience.",variant:"destructive"}),!1;let x=i.extracted_text;if(!x){o({title:"Extracting CV data...",description:"This may take a few moments."});const{data:c,error:s}=await v.functions.invoke("extract-cv-text",{body:{cvFileId:i.id}});if(s)throw s;const{data:n,error:a}=await v.from("cv_files").select("extracted_text").eq("id",i.id).single();if(a)throw a;if(x=n.extracted_text,!x)throw new Error("Text extraction failed. Please try again.")}const{data:u,error:y}=await v.functions.invoke("parse-work-experience",{body:{extractedText:x,cvFileId:i.id}});if(y)throw y;if(((r=u==null?void 0:u.workExperiences)==null?void 0:r.length)>0){const{data:c}=await v.from("xtern_assessments").select("id").eq("user_id",m).order("created_at",{ascending:!1}).limit(1).maybeSingle();c&&await v.from("xtern_assessment_experience").upsert({assessment_id:c.id,cv_file_id:i.id,work_experiences:u.workExperiences},{onConflict:"assessment_id"})}return o({title:"Sync complete!",description:"Your personal experience has been successfully synced."}),!0}catch(i){return console.error("CV sync error:",i),o({title:"Sync failed",description:i.message||"Failed to sync personal experience. Please try again.",variant:"destructive"}),!1}finally{d(!1)}},isSyncing:t}},Ne=({userId:t,hasCVUploaded:d,isSynced:o,onSyncComplete:p})=>{const{syncPersonalExperience:m,isSyncing:r}=ye(),i=async()=>{await m(t)&&p()};return d?e.jsx(j,{variant:o?"outline":"default",size:"sm",onClick:i,disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),"Syncing..."]}):o?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"h-4 w-4 mr-2"}),"Synced"]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Sync External Experience"]})}):e.jsx(j,{variant:"outline",size:"sm",disabled:!0,children:"No CV Uploaded"})},be=t=>{const{toast:d}=S(),[o,p]=f.useState({isPublic:!1,slug:null,isLoading:!0}),[m,r]=f.useState(!1),[i,l]=f.useState(!1);f.useEffect(()=>{if(!t)return;(async()=>{const{data:s}=await v.from("xterns_profiles").select("cv_slug, is_cv_public").eq("user_id",t).maybeSingle();p({isPublic:(s==null?void 0:s.is_cv_public)??!1,slug:(s==null?void 0:s.cv_slug)??null,isLoading:!1})})()},[t]);const x=f.useCallback(async c=>{if(!t)return;r(!0);const{error:s}=await v.from("xterns_profiles").update({is_cv_public:c}).eq("user_id",t);s?d({title:"Error",description:"Failed to update visibility",variant:"destructive"}):(p(n=>({...n,isPublic:c})),d({title:c?"CV is now public":"CV is now private",description:c?"Anyone with the link can view your CV":"Your CV is no longer publicly accessible"})),r(!1)},[t,d]),u=f.useCallback(async()=>
1{if(!t)return null;if(o.slug)return o.slug;l(!0);const{data:c,error:s}=await v.rpc("generate_cv_slug",{p_user_id:t});if(s)return d({title:"Error",description:"Failed to generate CV link",variant:"destructive"}),l(!1),null;const n=c;return p(a=>({...a,slug:n})),l(!1),n},[t,o.slug,d]),y=f.useCallback(c=>`${window.location.origin}/xtern/${c}`,[]);return{isPublic:o.isPublic,slug:o.slug,isLoading:o.isLoading,isToggling:m,isGenerating:i,togglePublic:x,generateSlug:u,getPublicUrl:y}},we=()=>({id:`draft_${Date.now()}`,company:"",role:"",duration:"",description:""}),Ce=({experiences:t,isSaving:d,onSave:o})=>{const[p,m]=f.useState(t),[r,i]=f.useState(!1),{toast:l}=S();f.useEffect(()=>{r||m(t)},[t,r]);const x=(s,n)=>{m(a=>a.map(g=>g.id===s?{...g,...n}:g))},u=()=>{m(s=>[...s,we()]),i(!0)},y=s=>{m(n=>n.filter(a=>a.id!==s))},c=async()=>{const s=p.map(a=>({...a,company:a.company.trim(),role:a.role.trim(),duration:a.duration.trim(),description:a.description.trim()})).filter(a=>a.company||a.role||a.duration||a.description);if(s.some(a=>!a.company||!a.role)){l({title:"Company and role are required",description:"Add both fields for each external experience entry.",variant:"destructive"});return}await o(s)&&i(!1)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"External Experience"})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Jobs, internships, freelance work, and other history from your platform CV."})]}),r?e.jsxs(j,{size:"sm",variant:"ghost",onClick:()=>{m(t),i(!1)},children:[e.jsx(Z,{className:"mr-1 h-4 w-4"}),"Cancel"]}):e.jsxs(j,{size:"sm",variant:"outline",onClick:()=>i(!0),children:[e.jsx(de,{className:"mr-1 h-4 w-4"}),"Edit"]})]}),!r&&e.jsxs("div",{className:"space-y-3",children:[t.length>0?t.map((s,n)=>e.jsxs("div",{className:"rounded-lg border border-border/60 p-3",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s.role||"Untitled role"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.company||"Company not set",s.duration?` | ${s.duration}`:""]})]},s.id||n)):e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-sm text-muted-foreground",children:"No external experience added yet."}),e.jsxs(j,{size:"sm",variant:"outline",onClick:u,children:[e.jsx(I,{className:"mr-1 h-4 w-4"}),"Add"]})]}),r&&e.jsxs("div",{className:"space-y-4",children:[p.map((s,n)=>e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm font-medium text-foreground",children:["Entry ",n+1]}),e.jsx(j,{size:"icon",variant:"ghost",onClick:()=>y(s.id),children:e.jsx(me,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(_,{htmlFor:`external-role-${s.id}`,children:"Role"}),e.jsx(P,{id:`external-role-${s.id}`,value:s.role,onChange:a=>x(s.id,{role:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(_,{htmlFor:`external-company-${s.id}`,children:"Company"}),e.jsx(P,{id:`external-company-${s.id}`,value:s.company,onChange:a=>x(s.id,{company:a.target.value})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(_,{htmlFor:`external-duration-${s.id}`,children:"Dates"}),e.jsx(P,{id:`external-duration-${s.id}`,placeholder:"Jan 2024 - Present",value:s.duration,onChange:a=>x(s.id,{duration:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(_,{htmlFor:`external-description-${s.id}`,children:"Responsibilities and achievements"}),e.jsx(ce,{id:`external-description-${s.id}`,value:s.description,onChange:a=>x(s.id,{description:a.target.value}),rows:3})]})]},s.id||n)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(j,{size:"sm",variant:"outline",onClick:u,children:[e.jsx(I,{className:"mr-1 h-4 w-4"}),"Add Entry"]}),e.jsxs(j,{size:"sm",onClick:c,disabled:d,children:[e.jsx(xe,{className:"mr-1 h-4 w-4"}
1),d?"Saving...":"Save Changes"]})]})]})]})},Se=t=>{const[d,o]=f.useState(!1),p=H(),{toast:m}=S();return{saveExternalExperiences:async i=>{if(!t)return!1;o(!0);try{const{data:l,error:x}=await v.from("cv_files").select("id").eq("user_id",t).order("uploaded_at",{ascending:!1}).limit(1).maybeSingle();if(x)throw x;let{data:u,error:y}=await v.from("xtern_assessments").select("id").eq("user_id",t).order("created_at",{ascending:!1}).limit(1).maybeSingle();if(y)throw y;if(!u){const{data:g,error:w}=await v.from("xtern_assessments").insert({user_id:t,assessment_type:"cv_profile"}).select("id").single();if(w)throw w;u=g}const c=i.map((g,w)=>({id:g.id||`external_exp_${Date.now()}_${w}`,company:g.company.trim(),role:g.role.trim(),duration:g.duration.trim(),description:g.description.trim()})),{error:s}=await v.from("xtern_assessment_experience").upsert({assessment_id:u.id,cv_file_id:(l==null?void 0:l.id)??null,work_experiences:c},{onConflict:l!=null&&l.id?"cv_file_id":"assessment_id"});if(s)throw s;const n=["xtern-cv-data",t],a=p.getQueryData(n);return a&&p.setQueryData(n,{...a,personalExperience:{...a.personalExperience??{},workExperiences:c},workExperiences:c}),p.invalidateQueries({queryKey:n}),m({title:"External experience updated"}),!0}catch(l){return console.error("External experience save error:",l),m({title:"Could not save experience",description:l.message||"Please try again.",variant:"destructive"}),!1}finally{o(!1)}},isSaving:d}},ns=()=>{const{cvData:t,isLoading:d,error:o,refetch:p,updateCVTemplateStyle:m}=le(),{user:r}=O(),{toast:i}=S(),[l,x]=f.useState(!1),[u,y]=f.useState(!1),{saveExternalExperiences:c,isSaving:s}=Se(r==null?void 0:r.id),{isPublic:n,slug:a,isLoading:g,isToggling:w,isGenerating:D,togglePublic:G,generateSlug:z,getPublicUrl:U}=be(r==null?void 0:r.id),X=()=>{p()},B=()=>{window.print()},Y=async h=>{y(!0);try{await m(h?"traditional":"modern"),i({title:h?"Traditional CV template enabled":"Modern CV template enabled",description:"Your CV preview and public CV link now use this template."})}catch(C){i({title:"Template update failed",description:C.message||"Please try again.",variant:"destructive"})}finally{y(!1)}},T=async()=>{const h=a||await z();if(!h)return;const C=U(h);try{await navigator.clipboard.writeText(C),x(!0),i({title:"Link copied!",description:"Public CV link copied to clipboard"}),setTimeout(()=>x(!1),2e3)}catch{i({title:"Failed to copy",description:"Please copy the link manually",variant:"destructive"})}},Q=async()=>{let h=a;if(h||(h=await z()),!h)return;const J=`https://cfcvcgojltawrodgtjnc.supabase.co/functions/v1/cv-og-metadata?slug=${encodeURIComponent(h)}`,K=`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(J)}`;window.open(K,"_blank","width=600,height=600")};return d?e.jsx(V,{children:e.jsxs("div",{className:"min-h-screen flex w-full bg-background",children:[e.jsx(L,{}),e.jsx(F,{className:"flex-1",children:e.jsx("div",{className:"flex items-center justify-center h-screen",children:e.jsx(pe,{className:"h-8 w-8 animate-spin text-primary"})})})]})}):o||!t?e.jsx(V,{children:e.jsxs("div",{className:"min-h-screen flex w-full bg-background",children:[e.jsx(L,{}),e.jsx(F,{className:"flex-1",children:e.jsx("div",{className:"flex items-center justify-center h-screen",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-destructive mb-4",children:o||"Failed to load CV data"}),e.jsx(j,{onClick:()=>window.location.reload(),children:"Reload"})]})})})]})}):e.jsxs(V,{children:[e.jsxs("div",{className:"min-h-screen flex w-full bg-background",children:[e.jsx(L,{}),e.jsxs(F,{className:"flex-1",children:[e.jsxs("header",{className:"sticky top-0 z-40 flex h-16 shrink-0 items-center gap-2 border-b bg-background px-4 print:hidden",children:[e.jsx(W,{className:"-ml-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-xl font-semibold text-foreground",children:"Dynamic CV"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your AI-powered, real-time resume"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{size:"sm",variant:"outline",onClick:T,disabled:!n,children:[l?e.jsx($,{className:"h-4 w-4 mr-1"}):e.jsx(R,{className:"h-4 w-4 mr-1"}),l?"Copied":"Share"]}),e.jsxs(j,{size:"sm",onClick:B,children:[e.jsx(ue,{className:"h-4 w-4 mr-1"}),"Download PDF"]})]})]}),e.jsxs("div",{className:"flex-1 space-y-6 p-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 print:hidden",children:[e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Signal Score"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:Math.round(t.dareyScore.total)})]}),e.jsx(he,{className:"h-8 w-8 text-yellow-500"})]})})}),e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Projects"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:t.projects.length})]}),e.jsx(ee,{className:"h-8 w-8 text-blue-500"})]})})}),e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Skills"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:t.skills.length})]}),e.jsx(se,{variant:"default",children:"Verified"})]})})}),e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Tasks Completed"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:t.achievements.totalStoriesCompleted})]}),e.jsx(fe,{className:"h-8 w-8 text-purple-500"})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsx(oe,{cvData:t,hideFloatingActions:!0})}),e.jsxs("div",{className:"space-y-6 print:hidden",children:[e.jsxs(N,{children:[e.jsx(k,{children:e.jsx(E,{className:"text-base",children:"CV Settings"})}),e.jsxs(b,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Traditional CV Template"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Switch to a plain-text resume layout for preview, download, and public CV links."})]}),e.jsx(A,{checked:t.cvTemplateStyle==="traditional",onCheckedChange:Y,disabled:u})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Sync your uploaded CV to add personal work experience"}),(r==null?void 0:r.id)&&e.jsx(Ne,{userId:r.id,hasCVUploaded:t.syncStatus.hasCVUploaded,isSynced:t.syncStatus.isSynced,onSyncComplete:X}),t.syncStatus.cvFileName&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["CV: ",t.syncStatus.cvFileName]})]})]})]}),e.jsxs(N,{children:[e.jsx(k,{children:e.jsxs(E,{className:"flex items-center gap-2 text-base",children:[e.jsx(te,{className:"h-4 w-4 text-primary"}),"Verified Xtern Experience"]})}),e.jsxs(b,{className:"space-y-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Platform experience is generated from verified pods, tasks, completion status, and enterprise project records. This section is system-generated and cannot be manually changed."}),t.platformExperience.projects.length>0?e.jsx("div",{className:"space-y-4",children:t.platformExperience.projects.map((h,C)=>e.jsx("div",{className:"rounded-lg border border-border/60 p-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:h.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h.podName})]})},`${h.podName||"pod"}-${h.title||"project"}-${C}`))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No verified Xtern experience recorded yet."})]})]}),e.jsx(N,{children:e.jsx(b,{className:"pt-6",children:e.jsx(Ce,{experiences:t.personalExperience.workExperiences,isSaving:s,onSave:c}
1)})}),e.jsxs(N,{children:[e.jsx(k,{children:e.jsx(E,{className:"text-base",children:"Share Your CV"})}),e.jsxs(b,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm text-foreground",children:"Make CV Public"}),e.jsx(ae,{children:e.jsxs(re,{children:[e.jsx(ie,{asChild:!0,children:e.jsx(je,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"})}),e.jsx(ne,{side:"top",className:"max-w-[260px] text-xs",children:"When enabled, your profile summary, skills, project experience, achievements, and Signal Score will be visible to anyone with the link."})]})})]}),e.jsx(A,{checked:n,onCheckedChange:G,disabled:w||g})]}),n&&e.jsxs(e.Fragment,{children:[a?e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Public URL"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(P,{value:U(a),readOnly:!0,className:"text-xs"}),e.jsx(j,{size:"sm",variant:"outline",onClick:T,children:l?e.jsx($,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})]}):e.jsxs(j,{size:"sm",className:"w-full",onClick:T,disabled:D,children:[e.jsx(ve,{className:"h-4 w-4 mr-1"}),D?"Generating...":"Generate & Copy Link"]}),a&&e.jsxs(j,{className:"w-full",size:"sm",variant:"outline",onClick:Q,children:[e.jsx(R,{className:"h-4 w-4 mr-1"}),"Share on LinkedIn"]})]})]})]}),e.jsxs(N,{children:[e.jsx(k,{children:e.jsx(E,{className:"text-base",children:"Achievements Summary"})}),e.jsxs(b,{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm",children:[e.jsxs("p",{className:"font-medium text-foreground",children:[t.achievements.assessmentsPassed," assessments passed"]}),e.jsx("p",{className:"text-muted-foreground",children:"Technical Skills"})]}),e.jsxs("div",{className:"text-sm",children:[e.jsxs("p",{className:"font-medium text-foreground",children:[t.achievements.podsCompleted," projects completed"]}),e.jsx("p",{className:"text-muted-foreground",children:"Team Collaboration"})]}),e.jsxs("div",{className:"text-sm",children:[e.jsxs("p",{className:"font-medium text-foreground",children:[t.achievements.totalStoriesCompleted," tasks completed"]}),e.jsx("p",{className:"text-muted-foreground",children:"Contributions"})]})]})]})]})]})]})]})]}),e.jsx("style",{children:` 2 @media print { 3 body { 4 print-color-adjust: exact; 5 -webkit-print-color-adjust: exact; 6 } 7 .print\\:hidden { 8 display: none !important; 9 } 10 .print\\:shadow-none { 11 box-shadow: none !important; 12 } 13 .print\\:border-0 { 14 border: 0 !important; 15 } 16 #cv-preview { 17 page-break-inside: avoid; 18 } 19 } 20 `})]})};export{ns 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.