1import{j as e}from"./vendor-ui-core.DP8knyZn.js";import{j as t,f as s,r as a}from"./vendor-react.BBoGJFYM.js";import{e as r,s as i,Y as n,i as o,S as c,B as l,l as d,v as m,L as p,I as u}from"./index.CdjOtu-m.js";import{C as x,d as h,a as v,b as j}from"./card.XsCnmSQ7.js";import{P as f}from"./progress.D-6ZFe_H.js";import{u as g}from"./vendor-media.DY6E_qVO.js";import{L as y,m as w,g as N,O as b,Z as _,a5 as k,q as I,N as S}from"./vendor-icons.BjAWwE8z.js";import"./vendor-supabase.DS-aP8MZ.js";import"./vendor-ui-forms.CjLBxE3d.js";import"./vendor-utils.BlEnRQrd.js";import"./vendor-ui-display.BT2Z6Vpo.js";import"./vendor-query.CfjDb5WU.js";import"./vendor-motion.DCvbjL6b.js";import"./vendor-charts.RWeJ_I16.js";const C=()=>{const{token:C}=t(),P=s(),{toast:F}=r(),[$,M]=a.useState("loading"),[R,T]=a.useState(null),[E,D]=a.useState(""),[U,A]=a.useState(""),[B,q]=a.useState(""),[z,O]=a.useState(""),[Y,L]=a.useState(null),[X,H]=a.useState(!1),[Z,G]=a.useState(0),[J,K]=a.useState("prompt");a.useEffect(()=>{C&&Q()},[C]);const Q=async()=>{M("loading");try{const{data:e,error:t}=await i.functions.invoke("accept-candidate-invitation",{body:{token:C}});if(t||(null==e?void 0:e.error))return D((null==e?void 0:e.error)||"Invalid or expired invitation link."),void M("error");
1if(e.already_accepted)return D("This invitation has already been accepted."),void M("error");T({email:e.email,full_name:e.full_name,job_title:e.job_title,company_name:e.company_name,interview_type:e.interview_type||"overall",duration_minutes:e.duration_minutes||30,job_description:e.job_description||e.job_description_summary||""}),A(e.full_name||""),M("details")}catch{D("Failed to load invitation details."),M("error")}},V=a.useCallback(async e=>{const t=await e.arrayBuffer(),s=new Uint8Array(t),a=await fetch(`${n}/functions/v1/parse-document?filename=${encodeURIComponent(e.name)}`,{method:"POST",headers:{apikey:o,"Content-Type":"application/octet-stream"},body:s});if(!a.ok)throw new Error(`HTTP ${a.status}`);const r=await a.json();if(!(null==r?void 0:r.success)||!(null==r?void 0:r.content))throw new Error("Failed to extract document content.");return r.content},[]),W=a.useCallback(async(e,t,s)=>{if(!C)throw new Error("Invitation token missing");const a=`${n}/functions/v1/save-candidate-resume-file?token=${encodeURIComponent(C)}&user_id=${encodeURIComponent(t)}&filename=${encodeURIComponent(e.name)}`,r=await fetch(a,{method:"POST",headers:{Authorization:`Bearer ${s}`,apikey:o,"Content-Type":e.type||"application/octet-stream"},body:await e.arrayBuffer()});if(!r.ok){let e="Failed to persist original resume file";try{const t=await r.json();e=(null==t?void 0:t.error)||e}catch{}throw new Error(e)}},[C]),ee=a.useCallback(async e=>{const t=null==e?void 0:e[0];if(!t)return;if(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document"].includes(t.type))if(t.size>10485760)F({title:"File too large",description:"Please upload a file smaller than 10MB",variant:"destructive"});else{H(!0),G(0);try{const e=setInterval(()=>{G(t=>t>=90?(clearInterval(e),90):t+15)},200),s=await V(t);clearInterval(e),G(100),q(s),O(t.name),L(t),F({title:"Resume processed",description:"Your resume has been parsed successfully."})}catch(s){F({title:"Upload failed",description:"Failed to process resume. Please try again.",variant:"destructive"}),G(0)}finally{H(!1)}}else F({title:"Invalid file type",description:"Please upload a PDF or DOCX document only",variant:"destructive"})},[F,V]),{getRootProps:te,getInputProps:se,isDragActive:ae,open:re}=g({onDrop:ee,accept:{"application/pdf":[".pdf"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[".docx"]},multiple:!1}),ie=async()=>{try{(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),K("granted")}catch{K("denied"),F({title:"Microphone Access Required",description:"Please allow microphone access to proceed with the interview.",variant:"destructive"})}};return"loading"===$?e.jsxs(e.Fragment,{children:[e.jsx(c,{title:"Invitation | SmartMentor.ai"}),e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(y,{className:"h-8 w-8 animate-spin text-primary"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(c,{title:"Interview Invitation | SmartMentor.ai"}),e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center px-4 py-4",children:e.jsxs("div",{className:"max-w-lg w-full space-y-3",children:["error"===$&&e.jsx(x,{children:e.jsxs("div",{className:"text-center p-6 space-y-3",children:[e.jsx(w,{className:"h-10 w-10 mx-auto text-destructive mb-1"}),e.jsx("h2",{className:"text-lg font-semibold",children:"Invitation Error"}),e.jsx("p",{className:"text-muted-foreground",children:E}),e.jsx(l,{onClick:()=>window.location.reload(),children:"Try Again"})]})}),"details"===$&&R&&e.jsxs(x,{children:[e.jsxs("div",{className:"flex justify-between items-center border-b border-gray-200 px-6 py-4",children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900",children:"Interview Invitation"}),e.jsx("img",{src:d,alt:"SmartMentor.ai",className:"h-24 w-auto"})]}),e.jsxs(h,{className:"space-y-3 pt-2 px-6 pb-6",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{className:"h-4 w-4 text-primary shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-base",children:R.job_title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:R.company_name})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(b,{className:"h-3.5 w-3.5"}),R.duration_minutes," min"]}),e.jsxs(m,{variant:"outline",className:"capitalize text-xs py-0",children:[R.interview_type," Interview"]})]}),R.job_description&&e.jsx("div",{className:"border-t pt-2 mt-1 max-h-[35vh] overflow-y-auto pr-1",children:e.jsx("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap leading-relaxed",children:R.job_description})})]}),e.jsx("div",{className:"text-center",children:e.jsx(m,{variant:"secondary",className:"text-xs",children:R.email})}),e.jsxs(l,{className:"w-full",onClick:()=>M("resume"),children:["Accept & Start Interview",e.jsx(_,{className:"h-4 w-4 ml-2"})]})]})]}),"resume"===$&&R&&e.jsxs(x,{children:[e.jsxs(v,{className:"text-center py-3 pb-1",children:[e.jsx(j,{className:"text-lg",children:"Prepare for Your Interview"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[R.job_title," at ",R.company_name]})]}),e.jsxs(h,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(p,{htmlFor:"name",className:"text-xs",children:"Your Name"}),e.jsx(u,{id:"name",value:U,onChange:e=>A(e.target.value),placeholder:"Enter your full name",className:"h-9"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(p,{className:"text-xs",children:"Email"}),e.jsx(u,{value:R.email,disabled:!0,className:"bg-muted h-9"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(p,{className:"text-xs",children:"Upload Resume"}),z?e.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-lg p-2",children:[e.jsx(I,{className:"h-4 w-4 text-green-500 shrink-0"}),e.jsx("span",{className:"text-xs truncate flex-1",children:z}),e.jsx(l,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>{O(""),q(""),L(null),G(0)},children:"Replace"})]}):e.jsxs("div",{...te(),className:"border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors "+(ae?"border-primary bg-primary/5":"border-muted-foreground
1/25 hover:border-primary/50"),children:[e.jsx("input",{...se()}),X?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{className:"h-6 w-6 animate-spin mx-auto text-primary"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Processing resume..."}),e.jsx(f,{value:Z,className:"h-1.5"})]}):e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-8 w-8 mx-auto text-muted-foreground mb-1"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Drag & drop or"," ",e.jsx("button",{type:"button",className:"text-primary underline",onClick:e=>{e.stopPropagation(),re()},children:"browse"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"PDF, DOCX (max 10MB)"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(p,{className:"text-xs",children:"Microphone Access"}),e.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-lg p-2",children:[e.jsx(S,{className:"h-4 w-4 shrink-0 "+("granted"===J?"text-green-500":"denied"===J?"text-destructive":"text-muted-foreground")}),e.jsx("span",{className:"text-xs flex-1",children:"granted"===J?"Microphone access granted":"denied"===J?"Microphone denied â enable in browser settings":"Microphone access needed for interview"}),"granted"!==J&&e.jsx(l,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:ie,children:"Allow"})]})]}),e.jsxs(l,{className:"w-full",onClick:async()=>{var e;if(C&&R)if(B){if("granted"===J||(await ie(),"denied"!==J)){M("starting");try{const{data:a,error:r}=await i.functions.invoke("start-corporate-interview",{body:{token:C,resume_content:B,candidate_name:U||R.full_name,candidate_email:R.email}});if(r||(null==a?void 0:a.error))throw new Error((null==a?void 0:a.error)||"Failed to start interview");if(await i.auth.setSession({access_token:a.session.access_token,refresh_token:a.session.refresh_token}),Y&&a.user_id&&(null==(e=a.session)?void 0:e.access_token)){let e=!1;for(let s=0;s<3&&!e;s++)try{await W(Y,a.user_id,a.session.access_token),e=!0}catch(t){s<2&&await new Promise(e=>setTimeout(e,700*(s+1)))}if(!e)try{const e=Y.name.split(".").pop()||"pdf",t=`${a.user_id}/${Date.now()}.${e}`,s=Y.name,{error:r}=await i.storage.from("resumes").upload(t,Y,{cacheControl:"3600",upsert:!0,contentType:Y.type});r||await i.from("profiles").update({resume_file_path:t,resume_filename:s}).eq("user_id",a.user_id)}catch(s){}}sessionStorage.setItem("corporate_candidate_mode","true"),sessionStorage.setItem("credits_pre_deducted","true"),sessionStorage.setItem("corporate_job_title",R.job_title),sessionStorage.setItem("corporate_company_name",R.company_name),sessionStorage.setItem("corporate_interview_type",R.interview_type),P(`/interview/${a.interview_id}`,{replace:!0})}catch(a){D(a.message||"Failed to start interview. Please try again."),M("error")}}}else F({title:"Resume Required",description:"Please upload your resume before starting.",variant:"destructive"})},disabled:!B||X,children:["Start Interview",e.jsx(_,{className:"h-4 w-4 ml-2"})]})]})]}),"starting"===$&&e.jsxs(x,{children:[e.jsxs(v,{className:"text-center py-4",children:[e.jsx(y,{className:"h-10 w-10 mx-auto animate-spin text-primary mb-1"}),e.jsx(j,{className:"text-lg",children:"Setting Up Your Interview..."})]}),e.jsx(h,{className:"text-center pt-0",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait while we prepare your session."})})]})]})})]})};export{C 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.