1import{j as e,y as h,r as i,u as F,a8 as $,q,t as O,a9 as V,aa as R,L as B,a1 as _,ab as G}from"./index-CFYEvtKP.js";import{a as H,P as J}from"./PlanUploadDropzone-Dgufvkgc.js";const I=[{id:"deduplication",label:"Checking",description:"Checking for duplicate documents"},{id:"parsing",label:"Parsing",description:"Extracting text from PDF"},{id:"extracting",label:"Extracting",description:"Extracting structured data"},{id:"hydrating",label:"Hydrating",description:"Populating plan schema"},{id:"embedding",label:"Embedding",description:"Generating searchable embeddings"},{id:"storing",label:"Storing",description:"Saving to database"}];function K(n){return n==="complete"?I.length:n==="failed"?-1:I.findIndex(a=>a.id===n)}function Y(n,a,r){if(r===n||a==="failed"&&!r)return"failed";const d=I.findIndex(u=>u.id===n),c=K(a);return c===-1?"pending":d<c?"completed":d===c?"active":"pending"}function W(n){const a=Math.floor(n/1e3),r=Math.floor(a/60),d=a%60;return r>0?`${r}:${d.toString().padStart(2,"0")}`:`${a}s`}function Q(){return e.jsx("svg",{className:"w-4 h-4 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true","data-testid":"stage-complete-icon",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}function X(){return e.jsxs("svg",{className:"w-4 h-4 text-white animate-spin",fill:"none",viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}function T(){return e.jsx("svg",{className:"w-4 h-4 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}function Z({currentStage:n,percentage:a,message:r,failedAtStage:d,showProgressBar:c=!0,compact:u=!1,elapsedMs:p,showElapsedTime:g=!1,className:f}){const l=n==="failed",C=n==="complete";return e.jsxs("div",{className:h("space-y-4",f),children:[c&&e.jsx(H,{value:a,variant:l?"error":C?"success":"default",showLabel:!0,animated:!0}),r&&e.jsxs("div",{className:h("flex items-center gap-2 text-sm",l?"text-destructive":"text-foreground-muted"),role:"status","aria-live":"polite",children:[l&&e.jsx("div",{className:"w-5 h-5 rounded-full bg-red-500 flex items-center justify-center","data-testid":"error-indicator",children:e.jsx(T,{})}),e.jsx("span",{children:r}),g&&p!==void 0&&e.jsxs("span",{className:"text-foreground-muted",children:["(",W(p),")"]})]}),e.jsx("ul",{role:"list",className:h("flex items-center justify-between",u?"gap-2":"gap-4"),children:I.map((x,v)=>{const t=Y(x.id,n,d),P=v===I.length-1;return e.jsxs("li",{className:"flex-1 flex items-center",role:"listitem","data-testid":`stage-${x.id}`,"data-status":t,"aria-current":t==="active"?"step":void 0,children:[e.jsxs("div",{className:"flex flex-col items-center gap-1.5 flex-shrink-0",children:[e.jsxs("div",{className:h("w-6 h-6 rounded-full flex items-center justify-center transition-colors",t==="completed"&&"bg-primary",t==="active"&&"bg-primary",t==="pending"&&"bg-surface-muted",t==="failed"&&"bg-destructive"),children:[t==="completed"&&e.jsx(Q,{}),t==="active"&&e.jsx(X,{}),t==="pending"&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-foreground-muted"}),t==="failed"&&e.jsx(T,{})]}),e.jsx("span",{className:h("text-xs font-medium text-center",t==="completed"&&"text-primary",t==="active"&&"text-primary",t==="pending"&&"text-foreground-muted",t==="failed"&&"text-destructive"),children:x.label})]}),!P&&e.jsx("div",{className:h("flex-1 h-0.5 mx-2",t==="completed"?"bg-primary":"bg-surface-muted"),"aria-hidden":"true"})]},x.id)})}),g&&p!==void 0&&!r&&e.jsxs("div",{className:"text-sm text-foreground-muted text-center",children:["Elapsed: ",W(p)]})]})}function ee(n){const{websocketUrl:a,userId:r,orgId:d,enabled:c=!0,onProgress:u,onError:p}=n,[g,f]=i.useState("disconnected"),[l,C]=i.useState({}),x=i.useRef(null),v=i.useRef(u),t=i.useRef(p);i.useEffect(()=>{v.current=u,t.current=p},[u,p]);const P=i.useCallback(()=>{const m=new URL(a);return m.searchParams.set("userId",r),d&&m.searchParams.set("orgId",d),m.toString()},[a,r,d]),S=i.useCallback(m=>{var j;try{const o=JSON.parse(m.data);if(o.type==="document_progress"){const k={documentId:o.payload.documentId,stage:o.payload.stage,percentage:o.payload.percentage,message:o.payload.message,timestamp:o.payload.timestamp};C(U=>({...U,[k.documentId]:k})),(j=v.current)==null||j.call(v,k)}}catch(o){console.error("Failed to parse WebSocket message:",o)}},[]),N=i.useCallback(()=>{var m,j;if(((m=x.current)==null?void 0:m.readyState)!==WebSocket.OPEN){f("connecting");try{const o=new WebSocket(P());o.onopen=()=>{f("connected")},o.onmessage=S,o.onerror=()=>{var k;f("error"),(k=t.current)==null||k.call(t,new Error("WebSocket connection error"))}
1,o.onclose=()=>{f("disconnected"),x.current=null},x.current=o}catch(o){f("error"),(j=t.current)==null||j.call(t,o instanceof Error?o:new Error("Failed to connect"))}}},[P,S]),y=i.useCallback(()=>{x.current&&(x.current.close(1e3,"Client disconnected"),x.current=null,f("disconnected"))},[]),L=i.useCallback(m=>l[m],[l]),E=i.useCallback(m=>{C(j=>{const o={...j};return delete o[m],o})},[]);return i.useEffect(()=>(c&&N(),()=>{y()}),[c,N,y]),{connectionStatus:g,isConnected:g==="connected",documentProgress:l,getProgressForDocument:L,clearProgress:E,connect:N,disconnect:y}}const se=()=>"wss://gzl7stnqgc.execute-api.us-east-1.amazonaws.com/prod";function te(){return e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}function A(){return e.jsx("svg",{className:"w-5 h-5 text-emerald-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})}function M({sponsorIdParam:n,backTo:a,sponsors:r,isMyCoverage:d,onSponsorPlanUploaded:c}){var D;const{user:u}=q(),p=O(),g=n!==null,f=d&&!g,[l,C]=i.useState(n??""),x=i.useMemo(()=>r.find(s=>
1s.sponsorId===l),[r,l]),v=((D=u==null?void 0:u.attributes)==null?void 0:D["custom:org_id"])||"demo-org",t=g&&l||v,P=(u==null?void 0:u.userId)||"demo-user",[S,N]=i.useState([]),{connectionStatus:y,isConnected:L,documentProgress:E,getProgressForDocument:m,clearProgress:j}=ee({websocketUrl:se(),userId:P,orgId:t,enabled:!0,onProgress:s=>{N(b=>b.map(w=>w.documentId===s.documentId?{...w,progress:s}:w))}}),o=y!=="connected",k=i.useCallback(s=>{p.success(`"${s.planName}" uploaded successfully!`),N(b=>[{documentId:s.documentId,planName:s.planName,planType:s.planType,uploadedAt:new Date},...b]),g&&l&&(V(R.plans(l)),c==null||c(l))},[p,g,l,c]),U=i.useCallback(s=>{p.error(`Upload failed: ${s}`)},[p]),z=i.useCallback(s=>{N(b=>b.filter(w=>w.documentId!==s)),j(s)},[j]);return i.useEffect(()=>{N(s=>s.map(b=>({...b,progress:m(b.documentId)})))},[E,m]),e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"bg-surface border-b border-border",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(B,{to:a,className:h("p-2 rounded-lg transition-colors","text-foreground-muted","hover:bg-surface-muted"),"aria-label":"Back to plans",children:e.jsx(te,{})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-foreground",children:"Upload Plan Document"}),e.jsx("p",{className:"text-sm text-foreground-muted",children:f?"Add your plan to track your own coverage":g?"Add a new benefit plan for the selected plan sponsor":"Add a new benefit plan to your organization"})]})]}),f&&e.jsxs(B,{to:"/admin",className:h("mt-3 inline-flex items-center gap-1 text-sm transition-colors","text-foreground-muted hover:text-foreground"),children:[e.jsx("span",{"aria-hidden":"true",children:"â"})," Back to portal"]})]})}),e.jsxs("main",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[e.jsxs("div",{className:"grid gap-8 lg:grid-cols-2",children:[e.jsxs("div",{className:"bg-card rounded-2xl shadow-elevation-soft border border-border p-6",children:[e.jsx("h2",{className:"text-lg font-medium text-foreground mb-6",children:"Select Document"}),g&&e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{htmlFor:"sponsorPicker",className:"block text-sm font-medium text-foreground mb-1.5",children:"Plan Sponsor"}),e.jsxs("select",{id:"sponsorPicker","data-testid":"sponsor-picker",value:l,onChange:s=>C(s.target.value),"aria-label":"Plan sponsor",className:h("w-full px-4 py-2.5 rounded-lg border transition-colors","bg-input","text-foreground","border-border focus:border-primary focus:ring-primary","focus:outline-none focus:ring-2 focus:ring-offset-0"),children:[e.jsx("option",{value:"",disabled:!0,children:"Select a plan sponsorâ¦"}),r.map(s=>e.jsx("option",{value:s.sponsorId,children:s.sponsorName},s.sponsorId))]}),e.jsx("p",{className:"mt-1.5 text-xs text-foreground-muted",children:x?`Uploading to ${x.sponsorName}.`:"Choose which plan sponsor this plan belongs to."})]}),e.jsx(J,{orgId:t,sponsorOrgId:g&&l||void 0,onUploadComplete:k,onError:U})]}),e.jsxs("div",{className:"bg-card rounded-2xl shadow-elevation-soft border border-border p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-lg font-medium text-foreground",children:"Processing Status"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:h("w-2 h-2 rounded-full",L?"bg-success":"bg-foreground-muted")}),e.jsx("span",{className:"text-xs text-foreground-muted",children:y==="connected"?"Live":y==="connecting"?"Connectingâ¦":"Live updates unavailable"})]})]}),S.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:h("w-16 h-16 mx-auto rounded-full flex items-center justify-center mb-4","bg-surface-muted"),children:e.jsx("svg",{className:"w-8 h-8 text-foreground-muted",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),e.jsx("p",{className:"text-foreground-muted",children:"Upload a plan to see processing status"})]}):e.jsxs("div",{className:"space-y-6",children:[o&&e.jsx("p",{className:"text-xs text-foreground-muted",role:"status",children:"Live updates unavailable â your upload is saved; processing continues in the background."}),S.map(s=>{var b,w;return e.jsxs("div",{className:h("p-4 rounded-lg border","bg-surface-muted","border-border"),children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-foreground",children:s.planName}),e.jsxs("p",{className:"text-xs text-foreground-muted",children:[_[s.planType]," ⢠Uploaded"," ",s.uploadedAt.toLocaleTimeString()]})]}),(((b=s.progress)==null?void 0:b.stage)==="complete"||!s.progress)&&e.jsx("button",{onClick:()=>z(s.documentId),className:h("p-1 rounded transition-colors","text-foreground-muted hover:text-foreground"),"aria-label":"Dismiss",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),s.progress?e.jsx(Z,{currentStage:s.progress.stage,percentage:s.progress.percentage,message:s.progress.message,showProgressBar:!0,compact:!0}):e.jsxs("div",{className:"flex items-center gap-2 text-sm text-success",children:[e.jsx(A,{}),e.jsx("span",{children:"Uploaded â saved and queued for processing."})]}),((w=s.progress)==null?void 0:w.stage)==="complete"&&e.jsxs("div",{className:"flex items-center gap-2 mt-3 text-sm text-success",children:[e.jsx(A,{}),e.jsx("span",{children:"Processing complete! Ready for queries."})]})]},s.documentId)})]})]})]}),e.jsxs("div",{className:"mt-8 bg-surface-muted rounded-xl p-6",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground mb-2",children:"What happens after upload?"}),e.jsxs("ul",{className:"text-sm text-foreground-muted space-y-1",children:[e.jsx("li",{children:"⢠The document is checked for duplicates"}),e.jsx("li",{children:"⢠Text is extracted from the PDF"}),e.jsx("li",{children:"⢠AI extracts structured benefit information"}),e.jsx("li",{children:"⢠Searchable embeddings are generated"}),e.jsx("li",{children:"⢠The plan becomes available for chat queries"})]})]})]})]})}function re({sponsorIdParam:n,backTo:a,isMyCoverage:r}){const{sponsors:d,refreshSponsors:c}=G(),u=i.useCallback(()=>{c==null||c()},[c]);return e.jsx(M,{sponsorIdParam:n,backTo:a,sponsors:d,isMyCoverage:r,onSponsorPlanUploaded:u})}function ae(){const[n]=F(),a=n.get("from"),r=a!==null&&/^\/(?!\/)/.test(a)?a:"/admin/plans",d=n.get("sponsorId"),c=r==="/my-coverage"||r==="/brokers/plan/personal";return d===null?e.jsx(M,{sponsorIdParam:null,backTo:r,sponsors:[],isMyCoverage:c}):e.jsx($,{children:e.jsx(re,{sponsorIdParam:d,backTo:r,isMyCoverage:c})})}export{ae as PlanUploadPage};
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.