1import{r as n,j as e,h as xe,i as ie}from"./react-vendor-CU6Sz31W.js";import{E as z,i as p,ax as _,aw as fe,c6 as M,u as je,C as ye,I as Z,S as ge,L as P,c7 as Y,c8 as J,c9 as H,ca as G,cb as T,az as A,dX as ve,dY as Ce,be as we}from"./index-DEXJEDAi.js";import{R as de}from"./RoutePageHeader-9W0v4VlT.js";import{u as be}from"./use-unsaved-changes-B6nL5Xdd.js";import"./calendar-RV2oTCrW.js";import{a as ae}from"./DataTableCard-BluwWKn_.js";import"./ExportCsvAction-BJr9eiP6.js";import"./patient-name-link-BAfQKbEs.js";import"./text-highlight-BFqqfcjs.js";import{u as Se}from"./usePracticeResource-b0KuqEmD.js";import{p as N,P as Pe,a as Re,l as ke,s as X}from"./PracticeFormSession-CU3yQgz1.js";import{P as Ne}from"./PracticeFormClarification-iL58wmtf.js";import{P as se}from"./PracticeFormRenderer-C6Jj5kJp.js";import{A as qe}from"./AccessDenied-Ba4b0-Uz.js";import{e as Fe,T as Ie,a as ne,b as B,c as Te,d as L}from"./table-CxPdvV_9.js";import{F as Ae,a as Oe}from"./FormBuilder-yfdeRhed.js";import{u as Ee,P as oe}from"./usePracticeRoute-BanfQY79.js";import"./firebase-w6DYUbFN.js";import"./payment-icons-Daq1K3F1.js";import"./RoutePageHeaderContent-FkxdZGox.js";import"./addWeeks-1hrFjz19.js";import"./index-BSuGcRaZ.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./pill-filter-CtZSNPVl.js";import"./date-picker-filter-Qp1kqu9t.js";import"./clear-filters-button-DmPemFGr.js";import"./modal-option-cards-Dksohkou.js";import"./offlineFormDrafts-CAcyqTIL.js";import"./shield-alert-DjOj07_r.js";import"./date-of-birth-picker-BQ2yrZNI.js";import"./quill-editor-D-DS6c39.js";import"./editor-D8UbQKN1.js";import"./audio-lines-GJL3_Ka2.js";import"./square-D7DkS8S2.js";import"./link-2-a8lhpkQ6.js";import"./code-BEcI87AG.js";import"./strikethrough-CiKozLGy.js";import"./underline-B_XtWKJP.js";import"./list-ordered-GNrnoOhB.js";import"./useEditorTranscription-CN2PcNng.js";import"./AssistantMarkdownContent-OjQ8GujO.js";import"./useOfflineFormDraftSync-D_7gScL0.js";import"./FormPreviewDialog-DrDrSHEH.js";import"./square-check-big-BIK4lrHD.js";import"./PatientFieldDefinitionDialog-BZBSN9SQ.js";import"./usePatientFieldDefinitions-DS6fhdRU.js";import"./patientFieldDefinitionCaches-PDqtgCkY.js";import"./modal-form-CqN5DZuv.js";import"./redo-2-DoWP9VFC.js";import"./sliders-horizontal-Bt65nPrH.js";import"./arrow-right-left-B4vnGqzD.js";import"./core.esm-DPjjHB-Z.js";import"./sortable.esm-Cj9Co3ow.js";import"./type-CJ1z0FOW.js";import"./circle-dot-B6AVn653.js";import"./user-round-c4EWOTq5.js";import"./keyboard-DLwPN9xF.js";import"./git-branch-BaXsltg0.js";import"./ban-DZ1NMSKK.js";import"./ellipsis-C0FvDuxB.js";import"./hash-C7GcXMrW.js";function De({practiceId:m,userDoc:c,showHeader:d=!0}){var v,a,k,F,O;const C=n.useCallback(()=>N(m,"/mine"),[m]),r=Se(C,{poll:!1}),[i,j]=n.useState(null),[o,y]=n.useState(null),[g,R]=n.useState("");async function h(l){y(l.formRequestId),R("");try{await N(m,`/requests/${encodeURIComponent(l.formRequestId)}/continue`,{method:"POST"}),await r.reload()}catch(q){R(q.message)}finally{y(null)}}const w=be({isDirty:!!(i&&i.kind!=="history"),onDiscard:()=>j(null)}),S=async()=>{j(null),await r.reload()},u=((v=r.data)==null?void 0:v.submissions)||[],b=((a=r.data)==null?void 0:a.forms)||[],t=[{id:"name",header:"Form",renderCell:l=>l.name},{id:"status",header:"Status",renderCell:l=>l.continueRequest?"Ready to continue":l.completed?"Complete":l.reviewStatus==="pending"?"Awaiting review":"Action needed"},{id:"action",header:"Action",renderCell:l=>{if(l.continueRequest)return e.jsx(p,{variant:"outline",size:"sm",disabled:!!o,onClick:()=>h(l),children:"Use saved answers"});const q=u.find($=>$.id===l.currentSubmissionId&&$.reviewStatus==="changes_requested"),W=l.reviewStatus==="pending";return!l.completed&&!W?e.jsx(p,{variant:"outline",size:"sm",onClick:()=>j({kind:q?"clarification":"form",form:l,submission:q}),children:q?"Respond to Practice":"Complete form"}):null}}],x=[{id:"name",header:"Form",renderCell:l=>{var q;return((q=l.formSnapshot)==null?void 0:q.name)||"Submitted form"}},{id:"status",header:"Status",renderCell:l=>({pending:"Awaiting review",approved:"Approved",changes_requested:"More information requested",rejected:"Not approved"})[l.reviewStatus]||"Submitted"},{id:"action",header:"Answers",renderCell:l=>e.jsx(p,{variant:"outline",size:"sm",onClick:()=>j({kind:"history",submission:l}),children:"View answers"})}];return e.jsxs("div",{className:"app-page-shell space-y-6",children:[d&&e.jsx(de,{title:"Forms",description:"Complete forms from your Practice and review your submitted answers."}),g&&e.jsx("p",{role:"alert",className:"text-sm text-status-danger",children:g}),r.error?e.jsx(z,{reason:"error",title:"Unable to load forms",description:r.error,action:e.jsx(p,{variant:"outline",onClick:r.reload,children:"Try again"})}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"font-display text-xl",children:"Requested forms"}),e.jsx(ae,{tableLabel:"Requested Practice forms",rows:b,columns:t,loading:r.loading,emptyMessage:e.jsx(z,{reason:"empty",title:"Youâre up to date",description:"Forms requested by your Practice will appear here."})})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsx("h2",{className:"font-display text-xl",children:"Your submissions"}),e.jsx(ae,{tableLabel:"Your Practice form submissions",rows:u,columns:x,loading:r.loading,emptyMessage:e.jsx(z,{reason:"empty",title:"No submitted forms yet",description:"Your saved submissions will appear here after you complete a form."})})]})]}),i&&e.jsx(_,{open:!0,size:"xl",title:((k=i.form)==null?void 0:k.name)||((O=(F=i.submission)==null?void 0:F.formSnapshot)==null?void 0:O.name)||"Your answers",description:i.kind==="history"?"Review the answers you submitted to your Practice.":"Complete the information requested by your Practice.",onOpenChange:l=>{l||w.requestClose(()=>j(null))},...w.guardProps,children:i.kind==="history"?e.jsx(se,{form:i.submission.formSnapshot,responses:i.submission.responses,userDoc:c,readOnly:!0}):i.kind==="clarification"?e.jsx(Ne,{practiceId:m,submission:i.submission,userDoc:c,onComplete:S}):e.jsx(Pe,{practiceId:m,formId:i.form.formId,formRequestId:i.form.formRequestId,onComplete:S})}),e.jsx(fe,{...w.confirmProps})]})}function ce({form:m,onClose:c}){const[d,C]=n.useState({});return e.jsx(_,{open:!0,onOpenChange:r=>{r||c()},size:"xl",title:m.name||"Form preview",description:"Preview the patient experience. Answers are not submitted.",footer:e.jsx(p,{type:"button",variant:"outline",onClick:c,children:"Close preview"}),children:e.jsx(M,{children:e.jsx(se,{form:m,responses:d,onChange:C,userDoc:{},previewMode:!0})})})}const Ue=["name","description","formType","sections","status","associations","recencyPolicy","publicEntry","reviewSettings","requiresReview","knowledgeBaseItemIds"],U=m=>Object.fromEntries(Ue.filter(c=>m[c]!==void 0).map(c=>[c,m[c]]));function le({showHeader:m=!0,readOnly:c=!1}){const{userDoc:d,currentUser:C}=je(),r=d==null?void 0:d.practiceId,[i,j]=n.useState(null),[o,y]=n.useState(""),[g,R]=n.useState(""),[h,w]=n.useState(null),[S,u]=n.useState(null),[b,t]=n.useState(null),[x,v]=n.useState(null),[a,k]=n.useState(null),[F,O]=n.useState(null),[l,q]=n.useState(!1),W=n.useRef(null),$=n.useRef(null),te=!c&&(d==null?void 0:d.userType)==="Practice Admin"&&!(d!=null&&d.requiresOnboarding),me=n.useMemo(()=>Re(r),[r]),E=n.useCallback(async()=>{try{y(""),j(await ke(r))}catch(s){y(s.message)}},[r]);n.useEffect(()=>{r&&E()},[r,E]);const K=(s={})=>w({name:"New form",formType:"intake",status:"draft",...s,id:crypto.randomUUID()}),ue=async(s,f={})=>{var V;const I=((V=f.persistedDraft)==null?void 0:V.formId)||h.id,ee=await X(r,I,U({...h,...s}));return await E(),w(null),ee};async function D(s){q(!0),y("");try{await s()}catch(f){y(f.message)}finally{q(!1)}}const re=((i==null?void 0:i.forms)||[]).filter(s=>`${s.name} ${s.formType}`.toLowerCase().includes(g.toLowerCase()));return e.jsxs("div",{className:"app-page-shell space-y-6 max-lg:space-y-3",children:[m&&e.jsx(de,{title:"Forms",description:"Manage this Practiceâs forms, responses, and review requests."}),e.jsxs(ye,{className:"space-y-4 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(Z,{"aria-label":"Search forms",placeholder:"Search forms",value:g,onChange:s=>R(s.target.value),className:"flex-1"}),e.jsx(p,{variant:"outline",onClick:()=>D(async()=>v(await N(r,"/activity"))),children:"Responses and requests"}),te&&e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"outline",onClick:()=>$.current.click(),children:"Import JSON"}),e.jsx(p,{variant:"outline",onClick:()=>W.current.click(),children:"Generate from file"}),e.jsx(p,{onClick:()=>K(),children:"Create form"})]})]}),e.jsx("input",{ref:$,type:"file",accept:"application/json,.json",className:"hidden","aria-label":"Import form JSON",onChange:s=>D(async()=>{var I;const f=(I=s.target.files)==null?void 0:I[0];f&&(K(U(JSON.parse(await f.text()))),s.target.value="")}
1)}),e.jsx("input",{ref:W,type:"file",accept:"application/pdf,image/jpeg,image/png,image/webp",className:"hidden","aria-label":"Generate form from document",onChange:s=>D(async()=>{var V;const f=(V=s.target.files)==null?void 0:V[0];if(!f)return;if(f.size>10*1024*1024)throw new Error("Choose a file under 10MB");const I=await new Promise((pe,he)=>{const Q=new FileReader;Q.onload=()=>pe(Q.result.split(",")[1]),Q.onerror=he,Q.readAsDataURL(f)}),ee=await N(r,"/generate",{method:"POST",filename:f.name,mimeType:f.type,fileBase64:I,formType:"intake"});K(ee.data),s.target.value=""})}),o&&e.jsx(z,{reason:"error",title:"Unable to complete this action",description:o,action:{label:"Retry",onClick:E}}),!i&&!o?e.jsx(ge,{}):re.length?e.jsxs(Fe,{children:[e.jsx(Ie,{children:e.jsxs(ne,{children:[e.jsx(B,{children:"Name"}),e.jsx(B,{children:"Type"}),e.jsx(B,{children:"Status"}),e.jsx(B,{children:"Version"}),e.jsx(B,{className:"text-right",children:"Actions"})]})}),e.jsx(Te,{children:re.map(s=>e.jsxs(ne,{children:[e.jsx(L,{children:s.name}),e.jsx(L,{children:s.formType}),e.jsx(L,{children:s.status}
1),e.jsx(L,{children:s.version||1}),e.jsx(L,{children:e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>t(s),children:"Preview"}),te&&e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>w(s),children:"Edit"}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>u(s),children:"Settings"}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>K({...U(s),name:`${s.name} copy`,status:"draft"}),children:"Duplicate"}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>D(async()=>{await N(r,`/${s.id}/status`,{method:"POST",status:s.status==="active"?"inactive":"active"}),await E()}),children:s.status==="active"?"Deactivate":"Publish"})]}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>D(async()=>O(await N(r,`/${s.id}/history`))),children:"History"}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>{const f=URL.createObjectURL(new Blob([JSON.stringify(U(s),null,2)],{type:"application/json"})),I=document.createElement("a");I.href=f,I.download=`${s.name}.json`,I.click(),URL.revokeObjectURL(f)},children:"Export"})]})})]},s.id))})]}):e.jsx(z,{reason:"empty",title:"No forms",description:"Create an intake or consent form for your Practice."})]}),l&&e.jsx("p",{role:"status",className:"text-sm text-content-secondary",children:"Savingâ¦"}),h&&e.jsx(Ae,{open:!0,title:h.name||"Form builder",onRequestClose:()=>w(null),children:e.jsx(Oe,{initialData:h,formType:h.formType,allowProductSelector:!0,productCategories:(i==null?void 0:i.categories)||[],dataAdapters:me,PreviewComponent:ce,onSave:ue,onClose:()=>w(null),onSaveAsNew:async s=>{const f=await X(r,crypto.randomUUID(),U({...h,...s}));return await E(),w(null),f},onAutosaveDraft:(s,f)=>X(r,(f==null?void 0:f.formId)||h.id,U({...h,...s})),offlineDraftConfig:{scopeType:"practice",scopeId:r,draftFormId:h.id,userId:(d==null?void 0:d.id)||(C==null?void 0:C.uid)}},h.id)}),S&&e.jsx(ze,{form:S,products:i.products,categories:i.categories,onClose:()=>u(null),onSave:s=>D(async()=>{await X(r,s.id,U(s)),u(null),await E()}),busy:l,practiceId:r}),b&&e.jsx(ce,{form:b,onClose:()=>t(null)}),F&&e.jsx(_,{open:!0,title:"Form history",description:"Saved versions and publishing changes.",onOpenChange:()=>O(null),children:e.jsx(M,{children:F.changes.length?F.changes.map(s=>e.jsxs("p",{className:"p-3 text-sm",children:["Version ",s.version,": ",s.action," by ",s.actorId]},s.id)):e.jsx(z,{reason:"empty",title:"No changes recorded"})})}),x&&e.jsxs(_,{open:!0,size:"xl",title:"Responses and requests",description:"Review submitted forms and outstanding requests.",onOpenChange:()=>v(null),children:[e.jsxs(M,{children:[x.submissions.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle p-3",children:[e.jsxs("span",{children:[s.formName," · ",s.reviewStatus," · ",s.userId]}),e.jsx(p,{variant:"outline",onClick:()=>k(s),children:"Review"})]},s.id)),x.requests.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle p-3",children:[e.jsxs("span",{children:["Request for ",s.patientId," · ",s.status]}),s.status==="pending"&&e.jsx(p,{variant:"outline",onClick:()=>D(async()=>{await N(r,`/requests/${s.id}/cancel`,{method:"POST"}),v(await N(r,"/activity"))}),children:"Cancel request"})]},s.id))]}),e.jsx(_e,{patients:x.patients||[],practiceId:r,forms:(i==null?void 0:i.forms)||[],products:(i==null?void 0:i.products)||[],onSaved:async()=>v(await N(r,"/activity"))})]}),a&&e.jsx($e,{practiceId:r,submission:a,onClose:()=>k(null),onSaved:async()=>{k(null),v(await N(r,"/activity"))}})]})}function ze({form:m,products:c,categories:d,onClose:C,onSave:r,busy:i,practiceId:j}){var w,S,u,b;const[o,y]=n.useState(m),g=o.associations||{applyToAll:!1,productIds:[],categoryIds:[],audienceTypes:["Patient"]},R=t=>y({...o,associations:{...g,...t}}),h=(t,x)=>{var v;return R({[t]:(v=g[t])!=null&&v.includes(x)?g[t].filter(a=>a!==x):[...g[t]||[],x]})};return e.jsx(_,{open:!0,size:"lg",title:"Form settings",description:"Set the audience, product coverage, and reuse rules.",onOpenChange:t=>{t||C()},footer:e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"outline",onClick:C,children:"Cancel"}),e.jsx(p,{type:"submit",form:"practice-form-settings",disabled:i,children:"Save settings"})]}),children:e.jsx("form",{id:"practice-form-settings",onSubmit:t=>{t.preventDefault(),r(o)},children:e.jsxs(M,{className:"space-y-4 p-4",children:[e.jsx(P,{htmlFor:"practice-form-type",children:"Form type"}),e.jsxs(Y,{value:o.formType,onValueChange:t=>y({...o,formType:t,...t==="consent"?{recencyPolicy:void 0}:{}}),children:[e.jsx(J,{id:"practice-form-type",children:e.jsx(H,{})}),e.jsx(G,{children:["intake","consent","network","client"].map(t=>e.jsx(T,{value:t,children:t==="network"?"Clinical staff onboarding":t==="client"?"Administrative onboarding":t},t))})]}),e.jsxs(P,{htmlFor:"practice-all-audience",className:"flex items-center gap-2",children:[e.jsx(A,{id:"practice-all-audience",checked:g.applyToAll,onCheckedChange:t=>R({applyToAll:t===!0,...t?{productIds:[],categoryIds:[]}:{}})}),"Required for the selected audience"]}),e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium",children:"Audience"}),["Patient","Practice Admin","Practice Staff","Practice Provider","Practice Provider Delegate"].map(t=>{var x;return e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(A,{checked:(x=g.audienceTypes)==null?void 0:x.includes(t),onCheckedChange:()=>h("audienceTypes",t)}),t]},t)}
1)]}),!g.applyToAll&&e.jsx(e.Fragment,{children:[["productIds","Products",c],["categoryIds","Categories",d]].map(([t,x,v])=>e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium",children:x}),v.map(a=>{var k;return e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(A,{checked:(k=g[t])==null?void 0:k.includes(a.id),onCheckedChange:()=>h(t,a.id)}),a.name]},a.id)})]},t))}),e.jsxs(P,{htmlFor:"practice-require-review",className:"flex items-center gap-2",children:[e.jsx(A,{id:"practice-require-review",checked:o.requiresReview===!0,onCheckedChange:t=>y({...o,requiresReview:t===!0})}),"Require review before forms are complete"]}),o.formType!=="consent"&&e.jsxs(e.Fragment,{children:[e.jsx(P,{htmlFor:"practice-form-recency",children:"Reuse"}),e.jsxs(Y,{value:((w=o.recencyPolicy)==null?void 0:w.mode)||"require_every_time",onValueChange:t=>y({...o,recencyPolicy:{mode:t,...t==="valid_for_days"?{days:30}:{}}}),children:[e.jsx(J,{id:"practice-form-recency",children:e.jsx(H,{})}),e.jsxs(G,{children:[e.jsx(T,{value:"require_every_time",children:"Every request"}),e.jsx(T,{value:"valid_for_days",children:"Valid for a number of days"})]})]}),((S=o.recencyPolicy)==null?void 0:S.mode)==="valid_for_days"&&e.jsx(Z,{"aria-label":"Form reuse days",type:"number",min:"1",max:"3650",value:o.recencyPolicy.days,onChange:t=>y({...o,recencyPolicy:{...o.recencyPolicy,days:Number(t.target.value)}})})]}),["intake","consent"].includes(o.formType)&&e.jsxs(P,{htmlFor:"practice-public-entry",className:"flex items-center gap-2",children:[e.jsx(A,{id:"practice-public-entry",checked:((u=o.publicEntry)==null?void 0:u.enabled)===!0,onCheckedChange:t=>y({...o,publicEntry:{...o.publicEntry||{},enabled:t===!0}})}),"Enable a public form link"]}),((b=o.publicEntry)==null?void 0:b.enabled)&&e.jsx(Z,{"aria-label":"Public form link",readOnly:!0,value:`${window.location.origin}/practice-form/${encodeURIComponent(j)}/${encodeURIComponent(m.id)}`})]})})})}function _e({practiceId:m,forms:c,products:d,patients:C,onSaved:r}){const[i,j]=n.useState(""),[o,y]=n.useState([]),[g,R]=n.useState([]),[h,w]=n.useState("none"),[S,u]=n.useState(""),[b,t]=n.useState(!1),x=n.useRef(crypto.randomUUID()),v=(a,k,F)=>k(a.includes(F)?a.filter(O=>O!==F):[...a,F]);return e.jsxs("form",{className:"space-y-3 p-4",onSubmit:async a=>{a.preventDefault(),t(!0),u("");try{await N(m,"/requests",{method:"POST",requestId:x.current,patientId:i,formIds:o,approvalProductIds:g,visitRequirement:h}),x.current=crypto.randomUUID(),j(""),y([]),R([]),await r()}catch(k){u(k.message)}finally{t(!1)}},children:[e.jsx(P,{htmlFor:"practice-request-patient",children:"Patient"}),e.jsxs(Y,{value:i,onValueChange:j,children:[e.jsx(J,{id:"practice-request-patient",children:e.jsx(H,{placeholder:"Choose a patient"})}),e.jsx(G,{children:C.map(a=>e.jsx(T,{value:a.id,children:a.fullName||a.email},a.id))})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-sm font-medium",children:"Forms"}),c.filter(a=>a.status==="active").map(a=>e.jsxs(P,{className:"flex items-center gap-2 py-1",children:[e.jsx(A,{checked:o.includes(a.id),onCheckedChange:()=>v(o,y,a.id)}),a.name]},a.id))]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-sm font-medium",children:"Products to approve after completion"}),d.filter(a=>a.status==="active"&&a.type==="product").map(a=>e.jsxs(P,{className:"flex items-center gap-2 py-1",children:[e.jsx(A,{checked:g.includes(a.id),onCheckedChange:()=>v(g,R,a.id)}),a.name]},a.id))]}),e.jsx(P,{htmlFor:"practice-request-review",children:"Clinical review"}),e.jsxs(Y,{value:h,onValueChange:w,children:[e.jsx(J,{id:"practice-request-review",children:e.jsx(H,{})}),e.jsxs(G,{children:[e.jsx(T,{value:"none",children:"No visit"}),e.jsx(T,{value:"async",children:"Chart review"}),e.jsx(T,{value:"sync",children:"Scheduled visit"})]})]}),S&&e.jsx("p",{role:"alert",className:"text-sm text-status-danger",children:S}),e.jsx(p,{type:"submit",disabled:b||!o.length||!i,children:"Request forms"})]})}function $e({practiceId:m,submission:c,onClose:d,onSaved:C}){const[r,i]=n.useState("approved"),[j,o]=n.useState([]),[y,g]=n.useState(""),[R,h]=n.useState(""),[w,S]=n.useState(!1);return e.jsx(_,{open:!0,size:"xl",title:c.formName,description:`Response revision ${c.revision} · ${c.reviewStatus}`,onOpenChange:u=>{u||d()},footer:e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"outline",onClick:d,children:"Close"}),e.jsx(p,{type:"submit",form:"practice-form-review",disabled:w,children:"Save review"})]}),children:e.jsx("form",{id:"practice-form-review",className:"space-y-4",onSubmit:async u=>{u.preventDefault(),S(!0),h("");try{await N(m,`/submissions/${c.id}/review`,{method:"POST",decision:r,revision:c.revision,questions:j,notes:y}),await C()}catch(b){h(b.message)}finally{S(!1)}},children:e.jsxs(M,{className:"space-y-4 p-4",children:[e.jsx(se,{form:c.formSnapshot,responses:c.responses,userDoc:{},readOnly:!0}),e.jsx(P,{htmlFor:"practice-review-decision",children:"Decision"}),e.jsxs(Y,{value:r,onValueChange:i,children:[e.jsx(J,{id:"practice-review-decision",children:e.jsx(H,{})}),e.jsxs(G,{children:[e.jsx(T,{value:"approved",children:"Approve"}),e.jsx(T,{value:"rejected",children:"Reject"}),e.jsx(T,{value:"changes_requested",children:"Request clarification"})]})]}),r==="changes_requested"&&c.formSnapshot.sections.map(u=>e.jsxs("fieldset",{children:[e.jsx("legend",{children:u.title}),Object.keys(c.responses[u.sectionId]||{}).map(b=>{var x;const t=`${u.sectionId}.${b}`;return e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(A,{checked:j.includes(t),onCheckedChange:()=>o(j.includes(t)?j.filter(v=>v!==t):[...j,t])}),((x=u.questions.find(v=>v.questionId===b))==null?void 0:x.question)||b]},t)}
1)]},u.sectionId)),e.jsx(P,{htmlFor:"practice-review-notes",children:"Notes"}),e.jsx(Z,{id:"practice-review-notes",value:y,onChange:u=>g(u.target.value)}),R&&e.jsx("p",{role:"alert",className:"text-sm text-status-danger",children:R})]})})})}function Ws({showHeader:m=!0}){const{loading:c,role:d,practiceId:C,userType:r,userDoc:i}=Ee();if(c)return e.jsx(ve,{title:"Forms",description:"Manage form catalogs, submissions, and intake workflows.",message:"Loading formsâ¦"});const j=()=>{if(C&&we(r,"Patient"))return e.jsx(De,{practiceId:C,userDoc:i,showHeader:m},C);switch(d){case oe.ADMIN:return e.jsx(le,{showHeader:m});case oe.PROVIDER:return e.jsx(le,{readOnly:!0,showHeader:m});default:return e.jsx(qe,{subject:"forms"})}};return e.jsxs(xe,{children:[e.jsx(ie,{index:!0,element:j()}),e.jsx(ie,{path:"*",element:e.jsx(Ce,{to:"/forms",replace:!0})})]})}export{Ws 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.