1import{j as e,r as o,p as F,N as H}from"./vendor-react-DfYGAhtm.js";import{bo as U,bn as $,bp as V,bq as Q}from"./vendor-icons-1odZwi-b.js";import{b5 as J,e as Y,b6 as q,a3 as M,aC as K,m as a,g as B,x as X}from"./index-DsBgCU7r.js";import"./missedContributionRetry-D0dCo6_S.js";import"./healthCategoryUi-C2_keODf.js";import{u as Z}from"./policiesApi-DYBxVdNQ.js";import{g as ee}from"./errors-BYKXB8DF.js";import{r as te,D as se,b as ne,e as oe,p as ie,c as D,m as re}from"./webToWebInspection-BgWNZmY_.js";import{i as _}from"./device-DbCxnG1h.js";import{V as k,a as G,T as m,F as P,H as N,v as O,S as ae,B as ce,h as le}from"./vendor-ui-DA_r9yXk.js";import{G as L}from"./routes-CNOe4p0Z.js";import"./vendor-state-BsBVN-fX.js";import"./vendor-forms-BP-7CbAP.js";import"./other-icon-DC1bN4dP.js";import"./savings-BJUwUGln.js";import"./routes-BR5I3bEX.js";import"./annuity-retirement-C1dZ1QHM.js";import"./health-ped-DAki1cTK.js";import"./professional-indemnity-Cx_HID73.js";import"./property-building-content-BPs_xKUv.js";import"./property-business-assets-DHEXMjWx.js";import"./property-home-content-BS-RQEdB.js";import"./savings-specialized-hA4moY7S.js";import"./savings-targeted-goals-BG697KhM.js";import"./useApiQuery-mQnoCtpJ.js";import"./api-BEJchXjA.js";const ue=({value:t,size:n=220,caption:s,ariaLabel:i="QR code"})=>e.jsxs(k,{gap:3,children:[e.jsx(G,{borderWidth:"2px",borderColor:"orange.500",borderRadius:"20px",bg:"white",p:{base:"10px",md:"12px"},lineHeight:0,boxShadow:"sm",children:e.jsx(J,{value:t,size:n,level:"M",marginSize:2,"aria-label":i,role:"img",style:{display:"block",height:"auto",maxWidth:"100%"}})}),s?e.jsx(m,{fontSize:{base:"sm",md:"md"},fontWeight:"semibold",color:"gray.600",textAlign:"center",children:s}):null]}),pe=async t=>{const n=await Y.post("/api/v1/witness-flow/sessions",t),{success:s,message:i,data:u}=n.data;if(!s||!u)throw new Error(i||"Could not start the inspection session.");return u},de=t=>{const n=o.useRef((()=>{const r=te();return r&&r.policyId===t?r:null})()).current,s=o.useRef(null),i=o.useRef(n?.sessionId??null),u=o.useRef(n?.expiresAt??null),[x,S]=o.useState(n?.policyId??null),[l,h]=o.useState(n?.sessionId??null),[p,f]=o.useState(n?.joinUrl??null),[y,R]=o.use
1State(n?.deviceDetails??null),[d,j]=o.useState(n?{status:n.status,currentStep:n.currentStep}:null),[A,I]=o.useState(n?.hasParticipant??!1),[v,w]=o.useState(!1),[E,g]=o.useState(""),C=o.useCallback(()=>{const r=s.current;r&&(r.off(),r.disconnect(),s.current=null)},[]),T=o.useCallback(async r=>{w(!0),g("");try{const c=await pe({policyId:r,ttlMinutes:se});u.current=c.expiresAt,i.current=c.sessionId,S(r),h(c.sessionId),f(ne({sessionId:c.sessionId,token:c.joinToken})),R(c.policy?.deviceDetails??null),j({status:c.status,currentStep:c.currentStep}),I(!1)}catch(c){g(ee(c)??"Could not start the inspection session. Please try again.")}finally{w(!1)}},[]);o.useEffect(()=>{if(!l)return;const r=q(K,{path:"/socket.io",transports:["websocket"],auth:{token:M.getAccessToken()??void 0}});return s.current=r,r.on("connect",()=>{oe(r,{sessionId:l,accessToken:M.getAccessToken()})}),r.on("WF_PARTICIPANT_JOINED",()=>{I(!0)}),r.on("WF_UPDATE",c=>{I(!0),j(z=>({status:c.status??z?.status??"WAITING",currentStep:c.currentStep??c.step??z?.currentStep??"INIT"}))}),()=>{C()}},[l,C]),o.useEffect(()=>{!l||!p||!x||!d||ie({sessionId:l,policyId:x,joinUrl:p,deviceDetails:y,status:d.status,currentStep:d.currentStep,hasParticipant:A,expiresAt:u.current})},[l,p,x,d,A,y]);const W=o.useCallback(()=>{C(),i.current&&D(),i.current=null,u.current=null,S(null),h(null),f(null),R(null),j(null),I(!1),w(!1),g("")},[C]),b=E?"failed":v?"creating":p?re({session:d,hasParticipant:A}):"idle";return o.useEffect(()=>{b==="completed"&&D()},[b]),{status:b,joinUrl:p,deviceDetails:y,isCreating:v,isComplete:b==="completed",hasActiveSession:l!=null,error:E,createSession:T,reset:W}},me={idle:{title:"Preparing inspectionâ¦",subtitle:""},creating:{title:"Preparing inspectionâ¦",subtitle:"Generating a secure inspection link."},waiting:{title:"Waiting for the inspecting phone",subtitle:"Scan the code above to connect and begin."},connected:{title:"Phone connected",subtitle:"The inspection is starting on the other phone."},recording:{title:"Inspection in progress",subtitle:"The inspecting phone is recording the inspection."},analyzing:{title:"Analyzing the inspection",subtitle:"Weâre reviewing the inspection. This only takes a moment."},completed:{title:"Inspection complete",subtitle:"Your device passed inspection. You can continue activation."},failed:{title:"Something went wrong",subtitle:"We couldnât start the inspection. Please try again."}},ge=t=>t==="waiting"||t==="creating",xe=t=>t==="connected"||t==="recording"||t==="analyzing",he=({status:t,joinUrl:n,deviceSummary:s,error:i,isComplete:u,onRetry:x,onDone:S})=>{const l=me[t],h=xe(t),p=!h&&!u,f=t!=="failed"&&ge(t)&&!!n;return e.jsxs(P,{direction:"column",flex:1,minH:0,gap:6,children:[e.jsxs(k,{gap:{base:5,md:6},align:"stretch",children:[h?e.jsx(m,{fontSize:{base:"xl",md:"2xl"},fontWeight:"bold",textAlign:"center",color:a.text.primary,children:"Follow the instructions on the inspecting phone"}):null,p?e.jsxs(k,{align:"center",gap:3,children:[e.jsx(m,{fontSize:{base:"xl",md:"2xl"},fontWeight:"bold",textAlign:"center",color:a.text.primary,children:"Inspect with another mobile device"}),e.jsx(m,{fontSize:"sm",textAlign:"center",color:a.text.gray,maxW:"420px",children:"To complete the inspection, use another mobile device to record a short video of this device by scanning the QR code."}),s?e.jsx(be,{deviceSummary:s}):null]}):null,f&&n?e.jsx(k,{gap:4,pt:1,children:e.jsx(ue,{value:n,size:200})}):null]}),e.jsx(k,{gap:4,align:"stretch",mt:"auto",children:t==="failed"?e.jsxs(e.Fragment,{children:[e.jsx(m,{fontSize:"sm",color:"red.500",textAlign:"center",children:i||l.subtitle}),e.jsx(B,{text:"Try again",icon:e.jsx(U,{}),iconPosition:"left",onClick:x})]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{status:t,title:l.title,subtitle:l.subtitle}),u?e.jsx(B,{text:"Continue",fullWidth:!0,onClick:S}):null]})})]})},fe=({status:t,title:n,subtitle:s})=>{const i=t==="connected"||t==="completed";return e.jsxs(N,{gap:3,align:"center",justify:"center",bg:i?"green.50":a.orange[50],border:"1px solid",borderColor:i?"green.200":a.orange[200],borderRadius:"xl",px:4,py:3.5,children:[i?e.jsx(O,{as:V,boxSize:5,color:"green.500"}):e.jsx(ae,{size:"sm",color:a.orange[600],borderWidth:"2px"}),e.jsxs(k,{gap:0,align:"start",children:[e.jsx(m,{fontSize:"sm",fontWeight:"semibold",color:a.text.primary,children:n}),s?e.jsx(m,{fontSize:"xs",color:a.text.gray,children:s}):null]})]})},be=({deviceSummary:t})=>e.jsxs(N,{gap:2,px:3,py:1.5,borderRadius:"full",bg:a.gray[50],border:"1px solid",borderColor:a.border.primary,maxW:"100%",children:[e.jsx(O,{as:$,boxSize:4,color:a.navy[400]}),e.jsx(m,{fontSize:"xs",fontWeight:"medium",color:a.text.label,lineClamp:1,children:t})]}),Se=t=>{if(!t)return"";
1const n=[t.brand,t.model].filter(Boolean).join(" ").trim(),s=t.imei?.trim();return n&&s?`${n} · IMEI: ${s}`:n||(s?`IMEI: ${s}`:"Gadget policy")},Ve=()=>{const[t]=F(),{navigate:n}=X(),s=t.get("policyId"),i=o.useMemo(()=>_(),[]),{data:u}=Z(s??""),x=o.useMemo(()=>Se(u?.data?.gadget),[u?.data?.gadget]),{status:S,joinUrl:l,isComplete:h,error:p,hasActiveSession:f,createSession:y,reset:R}=de(s),d=o.useRef(!1),j=o.useRef(null),[A,I]=o.useState();o.useLayoutEffect(()=>{const g=j.current;if(!g)return;const C=104,T=()=>{const W=g.getBoundingClientRect().top,b=window.innerHeight-W-C;I(b>360?`${b}px`:void 0)};return T(),window.addEventListener("resize",T),()=>window.removeEventListener("resize",T)},[]);const v=o.useCallback(()=>{!s||!_()||y(s)},[s,y]);o.useEffect(()=>{d.current||!s||!i||(d.current=!0,!f&&v())},[s,i,f,v]);const w=g=>{n(`/${L.PolicyActivation}?policyId=${s??""}`,{replace:!0,...g?.completed?{state:{gadgetInspectionCompleted:!0}}:{}})},E=()=>{R(),d.current=!0,v()};return s?i?e.jsxs(G,{px:4,pt:3,pb:5,children:[e.jsx(P,{align:"center",mb:3,children:e.jsxs(ce,{type:"button",variant:"plain",onClick:()=>w(),px:0,h:"auto",minW:"auto",gap:1.5,color:a.text.gray,fontSize:"sm",fontWeight:"medium","aria-label":"Back to activation",children:[e.jsx(Q,{size:18}),"Back"]})}),e.jsx(P,{justify:"center",children:e.jsxs(le,{ref:j,gap:0,w:"full",maxW:"460px",minH:A,bg:"white",border:"1px solid",borderColor:a.border.primary,borderRadius:"24px",px:{base:5,md:7},py:{base:6,md:7},boxShadow:"0 12px 40px rgba(31, 54, 95, 0.07)",children:[e.jsx(m,{fontSize:"xs",fontWeight:"bold",color:a.text.orange,textTransform:"uppercase",letterSpacing:"wider",textAlign:"center",mb:4,children:"Gadget inspection"}),e.jsx(he,{status:S,joinUrl:l,deviceSummary:x,error:p,isComplete:h,onRetry:E,onDone:()=>w({completed:!0})})]})})]}):e.jsx(H,{to:`/${L.PolicyActivation}?policyId=${s}`,replace:!0}):e.jsx(H,{to:"/home",replace:!0})};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.