1import{M as ge,u as ye,ab as ve,r as n,s as y,j as e,d as h,g as x,L as k,n as Ne,e as U,f as B,aD as F,a6 as i,R as c,v as _e,w as be,x as we,y as Ce,z as S,b as p,C as T,B as q,K as ke,Q as Se}from"./index-C9f1sBdt.js";import{P as Ae}from"./progress-CGtAcRhL.js";import{A as M,b as V}from"./alert-WDeXGbDw.js";import{C as Y}from"./circle-alert-CTrZhs3O.js";import{a as De}from"./addYears-vC-DW-zB.js";import{U as Pe}from"./upload-DGWC4qlF.js";import{C as te}from"./camera-BUd6BtEN.js";import{T as Ie}from"./trash-2-DUaW5RrQ.js";import{P as Ee}from"./plus-qClqWP7l.js";import{C as Ue}from"./calendar-DPS3k6sO.js";import{F as H}from"./file-text-Dp-dKqbl.js";import{f as Be}from"./format-DwvaiAgB.js";import"./addMonths--XFjMsAz.js";function Fe(L,m){return De(L,-m)}const A=[{id:"personal_details",label:"Personal Details",icon:ke},{id:"id_verification",label:"ID Verification",icon:te},{id:"address_history",label:"Address History",icon:Se},{id:"documents",label:"Documents",icon:H},{id:"complete",label:"Complete",icon:T}];function Qe(){var ee,se;const[L]=ge();ye();const m=L.get("token"),{toast:o}=ve(),[ae,O]=n.useState(!0),[f,j]=n.useState(!1),[a,re]=n.useState(null),[u,g]=n.useState(0),[z,W]=n.useState(""),[K,Q]=n.useState(""),[D,G]=n.useState(""),[J,X]=n.useState(""),[R,Z]=n.useState(""),[w,P]=n.useState([{address_line1:"",city:"",postcode:"",move_in_date:"",is_current:!0}]),[v,ne]=n.useState(null),[_,le]=n.useState(null),[I,ie]=n.useState([]),[$,ce]=n.useState([]),[b,N]=n.useState({});n.useEffect(()=>{m?oe():O(!1)},[m]);const oe=async()=>{try{const{data:s,error:t}=await y.from("tenant_referencing_requests").select("*").eq("access_token",m).single();if(t)throw t;if(!s){o({title:"Invalid link",description:"This referencing link is invalid or has expired",variant:"destructive"});return}re(s),s.date_of_birth&&W(s.date_of_birth),s.national_insurance_number&&Q(s.national_insurance_number),s.current_employment_status&&G(s.current_employment_status),s.employer_name&&X(s.employer_name),s.annual_income&&Z(s.annual_income.toString()),s.address_history&&Array.isArray(s.address_history)&&s.address_history.length>0&&P(s.address_history);const r=A.findIndex(l=>l.id===s.current_step);g(r>=0?r:0)}catch(s){console.error("Error fetching request:",s),o({title:"Error",description:"Failed to load referencing request",variant:"destructive"})}finally{O(!1)}},E=async(s,t)=>{const r=s.name.split(".").pop(),l=`${a==null?void 0:a.id}/${t}/${Date.now()}.${r}`,{error:d}=await y.storage.from("tenant-referencing").upload(l,s);if(d)return console.error("Upload error:",d),null;const{data:je}=y.storage.from("tenant-referencing").getPublicUrl(l);return je.publicUrl},de=async()=>{j(!0);try{const{error:s}=await y.from("tenant_referencing_requests").update({date_of_birth:z||null,national_insurance_number:K||null,current_employment_status:D||null,employer_name:J||null,annual_income:R?parseFloat(R):null,current_step:"id_verification"}).eq("access_token",m);if(s)throw s;g(1),o({title:"Details saved"})}catch(s){o({title:"Error",description:s.message,variant:"destructive"})}finally{j(!1)}},me=async()=>{j(!0);try{let s=a==null?void 0:a.id_document_url,t=a==null?void 0:a.selfie_url;v&&(N({...b,id:!0}),s=await E(v,"id-documents"),N({...b,id:!1})),_&&(N({...b,selfie:!0}),t=await E(_,"selfies"),N({...b,selfie:!1}));const{error:r}=await y.from("tenant_referencing_requests").update({id_document_url:s,selfie_url:t,current_step:"address_history"}).eq("access_token",m);if(r)throw r;g(2),o({title:"ID verification saved"})}catch(s){o({title:"Error",description:s.message,variant:"destructive"})}finally{j(!1)}},ue=async()=>{const s=w.filter(t=>t.address_line1&&t.postcode&&t.move_in_date);if(s.length===0){o({title:"Error",description:"Please add at least one address",variant:"destructive"});return}j(!0);try{const{error:t}=await y.from("tenant_referencing_requests").update({address_history:s,current_step:"documents"}).eq("access_token",m);if(t)throw t;g(3),o({title:"Address history saved"})}catch(t){o({title:"Error",description:t.message,variant:"destructive"})}finally{j(!1)}},he=async()=>{j(!0);try{const s=[...(a==null?void 0:a.bank_statements)||[]],t=[...(a==null?void 0:a.wage_slips)||[]];for(const l of I){N({...b,bank:!0});const d=await E(l,"bank-statements");d&&s.push(d)}for(const l of $){N({...b,wage:!0});
1const d=await E(l,"wage-slips");d&&t.push(d)}const{error:r}=await y.from("tenant_referencing_requests").update({bank_statements:s,wage_slips:t,current_step:"complete",form_completed_at:new Date().toISOString()}).eq("access_token",m);if(r)throw r;await y.functions.invoke("run-tenant-credit-check",{body:{requestId:a==null?void 0:a.id}}),g(4),o({title:"Documents uploaded",description:"Your application has been submitted for review"})}catch(s){o({title:"Error",description:s.message,variant:"destructive"})}finally{j(!1),N({})}},xe=()=>{P([...w,{address_line1:"",city:"",postcode:"",move_in_date:"",is_current:!1}])},pe=s=>{P(w.filter((t,r)=>r!==s))},C=(s,t,r)=>{const l=[...w];l[s]={...l[s],[t]:r},P(l)};if(!m)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx(h,{className:"max-w-md w-full",children:e.jsxs(x,{className:"pt-6 text-center",children:[e.jsx(Y,{className:"h-12 w-12 mx-auto text-destructive mb-4"}),e.jsx("h2",{className:"text-xl font-bold mb-2",children:"Invalid Link"}),e.jsx("p",{className:"text-muted-foreground",children:"This referencing link is missing or invalid. Please check the link sent to you."})]})})});if(ae)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(k,{className:"h-8 w-8 animate-spin text-primary"})});if(!a)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx(h,{className:"max-w-md w-full",children:e.jsxs(x,{className:"pt-6 text-center",children:[e.jsx(Y,{className:"h-12 w-12 mx-auto text-destructive mb-4"}),e.jsx("h2",{className:"text-xl font-bold mb-2",children:"Request Not Found"}),e.jsx("p",{className:"text-muted-foreground",children:"This referencing request could not be found or has expired."})]})})});const fe=(u+1)/A.length*100;return e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-background via-background to-primary/5 py-8 px-4",children:e.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(Ne,{className:"h-12 w-12 mx-auto text-primary"}),e.jsx("h1",{className:"text-2xl font-bold",children:"Tenant Referencing"}),e.jsxs("p",{className:"text-muted-foreground",children:["Complete your application for ",a.tenant_name]})]}),e.jsx(h,{children:e.jsx(x,{className:"pt-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:["Step ",u+1," of ",A.length]}),e.jsx("span",{className:"text-muted-foreground",children:(ee=A[u])==null?void 0:ee.label})]}),e.jsx(Ae,{value:fe,className:"h-2"}),e.jsx("div",{className:"flex justify-between",children:A.map((s,t)=>{const r=s.icon,l=t<u,d=t===u;return e.jsxs("div",{className:`flex flex-col items-center gap-1 ${l?"text-success":d?"text-primary":"text-muted-foreground"}`,children:[e.jsx("div",{className:`p-2 rounded-full ${l?"bg-success/20":d?"bg-primary/20":"bg-muted"}`,children:e.jsx(r,{className:"h-4 w-4"})}),e.jsx("span",{className:"text-xs hidden sm:block",children:s.label})]},s.id)})})]})})}),u===0&&e.jsxs(h,{children:[e.jsxs(U,{children:[e.jsx(B,{children:"Personal Details"}),e.jsx(F,{children:"Please provide your personal information"})]}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Date of Birth"}),e.jsx(c,{type:"date",value:z,onChange:s=>W(s.target.value),max:Be(Fe(new Date,18),"yyyy-MM-dd")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"National Insurance Number"}),e.jsx(c,{placeholder:"e.g. AB123456C",value:K,onChange:s=>Q(s.target.value.toUpperCase())})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Employment Status"}),e.jsxs(_e,{value:D,onValueChange:G,children:[e.jsx(be,{children:e.jsx(we,{placeholder:"Select status"})}),e.jsxs(Ce,{children:[e.jsx(S,{value:"employed",children:"Employed"}),e.jsx(S,{value:"self_employed",children:"Self-Employed"}),e.jsx(S,{value:"student",children:"Student"}),e.jsx(S,{value:"retired",children:"Retired"}),e.jsx(S,{value:"unemployed",children:"Unemployed"})]})]})]}),(D==="employed"||D==="self_employed")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Employer/Business N
1ame"}),e.jsx(c,{placeholder:"Enter employer name",value:J,onChange:s=>X(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Annual Income (£)"}),e.jsx(c,{type:"number",placeholder:"e.g. 35000",value:R,onChange:s=>Z(s.target.value)})]})]}),e.jsxs(p,{onClick:de,disabled:f,className:"w-full",children:[f?e.jsx(k,{className:"h-4 w-4 animate-spin mr-2"}):null,"Continue"]})]})]}),u===1&&e.jsxs(h,{children:[e.jsxs(U,{children:[e.jsx(B,{children:"ID Verification"}),e.jsx(F,{children:"Upload your ID document and a selfie"})]}),e.jsxs(x,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(i,{children:"ID Document (Passport, Driving License, or National ID)"}),e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-6 text-center",children:[a.id_document_url||v?e.jsxs("div",{className:"flex items-center justify-center gap-2 text-success",children:[e.jsx(T,{className:"h-5 w-5"}),e.jsx("span",{children:(v==null?void 0:v.name)||"Document uploaded"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Click to upload or drag and drop"})]}),e.jsx(c,{type:"file",accept:"image/*,.pdf",onChange:s=>{var t;return ne(((t=s.target.files)==null?void 0:t[0])||null)},className:"cursor-pointer"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(i,{children:"Selfie Photo"}),e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-6 text-center",children:[a.selfie_url||_?e.jsxs("div",{className:"flex items-center justify-center gap-2 text-success",children:[e.jsx(T,{className:"h-5 w-5"}),e.jsx("span",{children:(_==null?void 0:_.name)||"Selfie uploaded"})]}):e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Take a clear photo of yourself"})]}),e.jsx(c,{type:"file",accept:"image/*",capture:"user",onChange:s=>{var t;return le(((t=s.target.files)==null?void 0:t[0])||null)},className:"cursor-pointer"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{variant:"outline",onClick:()=>g(0),children:"Back"}),e.jsxs(p,{onClick:me,disabled:f||!v&&!a.id_document_url,className:"flex-1",children:[f?e.jsx(k,{className:"h-4 w-4 animate-spin mr-2"}):null,"Continue"]})]})]})]}),u===2&&e.jsxs(h,{children:[e.jsxs(U,{children:[e.jsx(B,{children:"Address History"}),e.jsx(F,{children:"Provide your addresses for the last 3 years"})]}),e.jsxs(x,{className:"space-y-4",children:[w.map((s,t)=>e.jsx(h,{className:"bg-secondary/30",children:e.jsxs(x,{className:"pt-4 space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(q,{variant:s.is_current?"default":"secondary",children:s.is_current?"Current Address":`Previous Address ${t}`}),t>0&&e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>pe(t),children:e.jsx(Ie,{className:"h-4 w-4 text-destructive"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Address Line 1"}),e.jsx(c,{placeholder:"Street address",value:s.address_line1,onChange:r=>C(t,"address_line1",r.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"City"}),e.jsx(c,{placeholder:"City",value:s.city,onChange:r=>C(t,"city",r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Postcode"}),e.jsx(c,{placeholder:"Postcode",value:s.postcode,onChange:r=>C(t,"postcode",r.target.value.toUpperCase())})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Move In Date"}),e.jsx(c,{type:"date",value:s.move_in_date,onChange:r=>C(t,"move_in_date",r.target.value)})]}),!s.is_current&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Move Out Date"}),e.jsx(c,{type:"date",value:s.move_out_date||"",onChange:r=>C(t,"move_out_date",r.target.value)})]})]})]})},t)),e.jsxs(p,{variant:"outline",onClick:xe,className:"w-full",children:[e.jsx(Ee,{className:"h-4 w-4 mr-2"}),"Add Previous Address"]}),e.jsxs(M,{children:[e.jsx(Ue,{className:"h-4 w-4"}),e.jsx(V,{children:"Please provide a complete 3-year address history. Add previous addresses if needed."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{variant:"outline",onClick:()=>g(1),children:"Back"}),e.jsxs(p,{onClick:ue,disabled:f,className:"flex-1",children:[f?e.jsx(k,{className:"h-4 w-4 animate-spin mr-2"}):null,"Continue"]})]})]})]}),u===3&&e.jsxs(h,{children:[e.jsxs(U,{children:[e.jsx(B,{children:"Financial Documents"}),e.jsx(F,{children:"Upload your bank statements and wage slips"})]}),e.jsxs(x,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(i,{children:"Bank Statements (Last 3 months)"}),e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-6 text-center",children:[e.jsx(H,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Upload your last 3 months of bank statements"}),e.jsx(c,{type:"file",accept:".pdf,image/*",multiple:!0,onChange:s=>ie(Array.from(s.target.files||[])),className:"cursor-pointer"}),I.length>0&&e.jsxs("div",{className:"mt-2 text-sm text-success",children:[I.length," file(s) selected"]}),a.bank_statements&&a.bank_statements.length>0&&e.jsxs(q,{variant:"secondary",className:"mt-2",children:[a.bank_statements.length," previously uploaded"]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(i,{children:"Wage Slips / Proof of Income (Last 3 months)"}),e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-6 text-center",children:[e.jsx(H,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Upload your last 3 months of wage slips or proof of income"}),e.jsx(c,{type:"file",accept:".pdf,image/*",multiple:!0,onChange:s=>ce(Array.from(s.target.files||[])),className:"cursor-pointer"}),$.length>0&&e.jsxs("div",{className:"mt-2 text-sm text-success",children:[$.length," file(s) selected"]}),a.wage_slips&&a.wage_slips.length>0&&e.jsxs(q,{variant:"secondary",className:"mt-2",children:[a.wage_slips.length," previously uploaded"]})]})]}),e.jsxs(M,{children:[e.jsx(Y,{className:"h-4 w-4"}),e.jsx(V,{children:"All documents are securely stored and will only be used for referencing purposes."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{variant:"outline",onClick:()=>g(2),children:"Back"}),e.jsxs(p,{onClick:he,disabled:f||I.length===0&&!((se=a.bank_statements)!=null&&se.length),className:"flex-1",children:[f?e.jsx(k,{className:"h-4 w-4 animate-spin mr-2"}):null,"Submit Application"]})]})]})]}),u===4&&e.jsx(h,{className:"border-success/50",children:e.jsxs(x,{className:"pt-6 text-center space-y-4",children:[e.jsx("div",{className:"w-16 h-16 bg-success/20 rounded-full flex items-center justify-center mx-auto",children:e.jsx(T,{className:"h-8 w-8 text-success"})}),e.jsx("h2",{className:"text-2xl font-bold",children:"Application Submitted"}),e.jsx("p",{className:"text-muted-foreground",children:"Thank y
1ou for completing your referencing application. Your information has been submitted for review."}),e.jsx(M,{children:e.jsx(V,{children:"A credit check will be performed and the results will be shared with your letting agent. You will be notified once the process is complete."})})]})})]})})}export{Qe 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.