1import{a as N,b as V,j as e,C as z,b2 as D,S as O,V as Q,H as F,T as k,L as W,B,f as L,l as $}from"./index-DN2b6gf5.js";import{u as A,r,L as E,a as K}from"./react-vendor-DRshJiK8.js";import{N as M,V as U}from"./DemandPanel-C3yluBmp.js";import{f as _}from"./feedbackApi-DrU684cu.js";import{W as Y,a as G}from"./wrap-C0U6rsSK.js";const I=t=>t&&!t.startsWith("{{")?t:null,R=({question:t,initialChoice:c,signedIn:l,token:u,source:i,campaign:d,autoVote:x,depth:o})=>{const j=K(),[a,h]=r.useState(c),[m,f]=r.useState("choose"),[y,v]=r.useState(null),S=r.useRef(!1),n=V("blue.50","blue.900"),p=V("gray.600","gray.300"),C=l||!!u,b=t.options.find(s=>s.value===a)??null,w=async s=>{var g;if(h(s),!!C){f("saving");try{await _.pollVote({question_key:t.key,value:s,source:i,campaign:d,...l?{}:{token:u}}),f("voted");const T=(g=t.options.find(P=>P.value===s))==null?void 0:g.follow_up_key;T&&o<2&&_.pollQuestion(T).then(P=>v(P.question)).catch(()=>v(null))}catch{f("error")}}};r.useEffect(()=>{x&&l&&c&&!S.current&&(S.current=!0,w(c))},[x,l,c]);const H=()=>{const s=new URLSearchParams({q:t.key});return a&&s.set("v",a),s.set("src",i),d&&s.set("c",d),$(`/feedback/vote?${s.toString()}`)};return e.jsxs(B,{role:"group","aria-label":t.prompt,mt:o>0?8:0,children:[e.jsx(F,{as:o>0?"h2":"h1",size:o>0?"md":"lg",mb:2,children:t.prompt}),o===0&&e.jsx(k,{color:p,mb:4,children:M}),m==="voted"&&b?e.jsx(U,{questionKey:t.key,value:b.value,label:b.label,allowText:t.allow_followup_text,token:l?null:u}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{spacing:2,role:"radiogroup","aria-label":t.prompt,children:t.options.map(s=>{const g=s.value===a;return e.jsx(G,{children:e.jsxs(L,{variant:"outline",role:"radio","aria-checked":g,bg:g?n:void 0,borderColor:g?"blue.500":void 0,isDisabled:m==="saving",onClick:()=>C&&o>0?w(s.value):h(s.value),children:[s.label,s.available?" · available now":""]})},s.value)})}),o===0&&e.jsx(B,{mt:5,children:C?e.jsx(L,{colorScheme:"blue",isDisabled:!a,isLoading:m==="saving",onClick:()=>a&&w(a),children:b?`Count my vote: ${b.label}`:"Pick one to vote"}):e.jsx(L,{colorScheme:"blue",isDisabled:!a,onClick:()=>j(H()),children:"Sign in to vote"})}),m==="error"&&e.jsx(k,{mt:3,color:p,role:"alert",children:"That vote didn't go through. The link may have expired; sign in and try again."})]}),y&&e.jsx(R,{question:y,initialChoice:null,signedIn:l,token:u,source:i,campaign:d,autoVote:!1,depth:o+1})]})},te=()=>{const[t,c]=A(),{user:l,isLoading:u}=N(),[i,d]=r.useState(null),[x,o]=r.useState("loading"),j=V("gray.600","gray.300"),a=t.get("q")||"",h=t.get("v"),m=t.get("src")==="newsletter"?"newsletter":"direct",f=t.get("c"),[y]=r.useState(()=>I(t.get("pt")));r.useEffect(()=>{if(t.has("pt")){const n=new URLSearchParams(t);n.delete("pt"),c(n,{replace:!0})}},[t,c]),r.useEffect(()=>{if(!a){o("missing");return}let n=!1;return _.pollQuestion(a).then(p=>{n||(p.migrated&&p.question?(d(p.question),o("ready")):o("missing"))}).catch(()=>!n&&o("missing")),()=>{n=!0}},[a]);const v=!!(l!=null&&l.is_registered),S=i&&h&&i.options.some(n=>n.value===h)?h:null;return e.jsxs(z,{maxW:"container.md",py:{base:8,md:12},children:[e.jsxs(D,{children:[e.jsx("title",{children:"Help shape ChemIllusion"}),e.jsx("meta",{name:"robots",content:"noindex"})]}),x==="loading"||u?e.jsx(O,{"aria-label":"Loading poll"}):x==="missing"||!i?e.jsxs(Q,{align:"start",spacing:3,children:[e.jsx(F,{size:"lg",children:"This poll has closed"}),e.jsx(k,{color:j,children:"You can still tell us what would help on your account page."}),e.jsx(W,{as:E,to:"/account",color:"blue.500",children:"Go to Help shape ChemIllusion"})]}):e.jsx(R,{question:i,initialChoice:S,signedIn:v,token:y,source:m,campaign:f,autoVote:!0,depth:0}),e.jsxs(k,{fontSize:"sm",color:j,mt:10,children:["Voting doesn't change your email preferences, and we never show individual votes.",v&&e.jsxs(e.Fragment,{children:[" ",e.jsx(W,{as:E,to:"/account",color:"blue.500",children:"See every direction on your account page"}),"."]})]})]})};export{te 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.