1import{r as m,u as v,j as e,R as N}from"./index-WlGeQg1f.js";import{u as Q,b as _,F as $,L as A}from"./components-CP2-rEgA.js";import{C as k}from"./circle-check-big-CnkHfioI.js";import"./createLucideIcon-Bh05ASVS.js";try{let s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new s.Error().stack;t&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[t]="72b64b1a-78ee-4af9-a754-e2dee3c4951d",s._sentryDebugIdIdentifier="sentry-dbid-72b64b1a-78ee-4af9-a754-e2dee3c4951d")}catch{}const P=()=>[{title:"Power to Live | Questionnaire",description:"Welcome to Power to Live"}];function F(){const s=Q(),t=_(),[i,o]=m.useState({}),[a,c]=m.useState([]),l=m.useRef({}),d=v(),b=(n,r)=>{o(u=>({...u,[n]:r})),c(u=>u.filter(y=>y!==n))},p=()=>{const n=s.questionnaire.questions.filter(r=>!i[r.id]).map(r=>r.id);return n.length>0?(c(n),f(n[0]),!1):!0},f=n=>{var r;l.current[n]&&((r=l.current[n])==null||r.scrollIntoView({behavior:"smooth",block:"center"}))},g=n=>{p()||n.preventDefault()};if(s.completed_at)return e.jsx(x,{title:"Questionnaire Completed",description:"You have already completed this questionnaire"});if(t!=null&&t.success)return e.jsx(x,{title:"Questionnaire Completed",description:"Thanks for completing this questionnaire"});const j=s.questionnaire.questions.length,w=Object.keys(i).length/j*100;return e.jsx("div",{className:"min-h-screen bg-gray-50 p-4 md:p-8",children:e.jsx("div",{className:"mx-auto max-w-2xl",children:e.jsxs("div",{className:"overflow-hidden rounded-xl bg-white shadow-lg",children:[e.jsxs("div",{className:"border-b p-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:s.questionnaire.title})}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:s.questionnaire.description})]}),e.jsx("div",{className:"p-6",children:e.jsxs($,{method:"POST",className:"space-y-8",onSubmit:g,id:"questionnaire",children:[s.questionnaire.questions.map(n=>e.jsx(h,{question:n,error:a.includes(n.id)?"Please select an answer":null,selectedAnswer:i[n.id],onAnswerChange:r=>b(n.id,r),ref:r=>l.current[n.id]=r},n==null?void 0:n.id)),e.jsx("div",{className:"relative h-2 overflow-hidden rounded-full bg-gray-100",children:e.jsx("div",{className:"absolute left-0 top-0 h-full bg-blue-500 transition-all duration-300",style:{width:`${w}%`}})}),e.jsx("input",{type:"hidden",name:"answers",value:JSON.stringify(Object.entries(i).map(([n,r])=>({question_id:parseInt(n),answer_option_id:r})))})]})}),e.jsx("div",{className:"space-y-4 border-t bg-gray-50 p-6",children:e.jsx("button",{type:"submit",form:"questionnaire",className:"w-full btn-primary",children:d.state!=="idle"?"Submitting":"Submit Answers"})})]})})})}function x({title:s,description:t}){return e.jsx("div",{className:"min-h-screen bg-gray-50 p-4 flex items-center justify-center",children:e.jsxs("div",{className:"w-full max-w-md overflow-hidden rounded-lg bg-white border",children:[e.jsxs("div",{className:"p-6 text-center",children:[e.jsx("div",{className:"mb-4 flex justify-center",children:e.jsx(k,{className:"h-12 w-12 text-green-500"})}),e.jsx("h1",{className:"text-2xl font-bold text-green-700 mb-2",children:s}),e.jsx("p",{className:"text-gray-600",children:t})]}),e.jsx("div",{className:"px-6 py-4 flex justify-center",children:e.jsx(A,{to:"https://www.powertolive.uk/",className:"btn-primary",children:"Back to Home"})})]})})}const C=({selected:s})=>e.jsx("div",{className:`mr-3 flex h-5 w-5 items-center justify-center rounded-full border ${s?"bg-blue-500":"border-gray-300"}`,children:e.jsx("div",{className:`h-2.5 w-2.5 rounded-full bg-white ${s?"opacity-100":"opacity-0"}`})}),I=({text:s,selected:t})=>e.jsx("span",{className:`flex-grow text-sm ${t?"text-blue-600 font-medium":"text-gray-700"}`,children:s}),S=({option:s,questionId:t,isSelected:i,onSelect:o})=>{const a=`question_${t}_option_${s.id}`;return e.jsxs("label",{htmlFor:a,className:`flex cursor-pointer items-center rounded-lg border p-4 transition-colors duration-200 hover:bg-gray-50 2 ${i?"border-blue-500 bg-blue-50/50":"border-gray-200"}`,children:[e.jsx("input",{id:a,type:"radio",name:`question_${t}`,value:s.id,checked:i,onChange:()=>
2o(s.id),className:"sr-only"}),e.jsx(C,{selected:i}),e.jsx(I,{text:s.text,selected:i})]})},O=({options:s,questionId:t,selectedAnswer:i,onAnswerChange:o,hasError:a,labelledBy:c,describedBy:l})=>e.jsx("div",{className:"space-y-3",role:"radiogroup","aria-labelledby":c,"aria-describedby":l,"aria-invalid":a?"true":void 0,children:s.map(d=>e.jsx(S,{option:d,questionId:t,isSelected:i===d.id,onSelect:o},d.id))}),R=({message:s,id:t})=>s?e.jsx("p",{id:t,className:"text-red-500 text-sm mt-1",role:"alert",children:s}):null,B=({text:s,id:t})=>e.jsx("h3",{id:t,className:"font-medium text-gray-900",children:s}),h=N.forwardRef(({question:s,error:t,selectedAnswer:i,onAnswerChange:o},a)=>{const c=`question-${s.id}`,l=`${c}-heading`,d=`${c}-error`;return e.jsxs("div",{className:"space-y-4",ref:a,children:[e.jsx(B,{text:s.text,id:l}),e.jsx(O,{options:s.answer_options,questionId:s.id,selectedAnswer:i,onAnswerChange:o,hasError:!!t,labelledBy:l,describedBy:t?d:void 0}),e.jsx(R,{message:t||null,id:d})]})});h.displayName="Question";export{F as default,P as meta}; 3//# sourceMappingURL=questionnaire._id-C-cONszZ.js.map
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.