1import{n as e}from"./antdProComponents-CFjaKfty.js";import{a1 as v,a3 as j,S as P,a7 as Y,a0 as G}from"./antdForm-D_29pKbP.js";import{g as V,b as $,C as w,ay as g,p as E,Y as I,bt as B}from"./index-CR8yoNY4.js";import{l as M,r as A,j as W}from"./react-_5RlvHhi.js";import{g as J,f as X}from"./fetchSurvey-DO4O_yOH.js";import{cm as F,aG as Q}from"./antdBase-DlFOY6T8.js";import{C as Z}from"./index-JbxCT1Y9.js";import{q as x,b as q,p as ee,o as se,d as ae,r as te}from"./Paragraph-CTxKj3uA.js";import{U as H,u as re,L as ne,q as K}from"./antdIcons-BdMX_pWi.js";import{x as S}from"./utils-BGnmWEL9.js";import{P as ie}from"./PreviewSurvey-YzlRa1NM.js";import"./styles-DV1BBPH2.js";import{h as le,e as U,C as ce,A as oe,c as de,d as ue,a as pe,L as me,B as xe,p as he}from"./chart-BVWW38sX.js";import{u as O,c as ve,b as ye}from"./query-BM65dpYW.js";import{S as k}from"./antdTable-CU40bWxf.js";import"./antdModal-tqe9k7Ax.js";import"./pdfjs-Jc8nWIli.js";import"./jspdf-Dp8Wz4gx.js";import"./reactPdf-CWXH5nfV.js";import"./antdMaskInput-Bpz7D-sT.js";import"./antdProTable-Ds9khEp6.js";import"./others-D2FK10gv.js";import"./x6-8W7Bzdfz.js";import"./tiptap-BdEHFol7.js";import"./pdfLib-_sLH-ZSH.js";const _e=async({surveyId:l,surveyInfo:n,questions:d})=>{n!==null&&await V.patch(`/api/v2/qa_new/surveys/${l}/`,n).then(({data:u})=>u),d.questions_data!==null&&await V.post(`/api/v2/qa_new/surveys/${l}/questions/replace/`,d)},je=async l=>await V.get(`/api/v2/qa_new/surveys/${l}/answers/?page_size=50000`).then(({data:n})=>n==null?void 0:n.results),fe=async l=>await V.get(`/api/v2/qa_new/surveys/${l}/summary_statistics/`).then(n=>n.data),{TextArea:ge}=j,be=({form:l,questions:n,setQuestions:d})=>{const{t:u}=$(),c=(s,r)=>{if(s===x[0].id)return e.jsx(v.Item,{name:r.text,children:e.jsx(j,{disabled:!0})});if(s===x[1].id)return e.jsx(v.Item,{name:r.text,children:e.jsx(ge,{disabled:!0})});if(s===x[2].id)return e.jsx(e.Fragment,{children:r.options.payload.choices.map((a,t)=>e.jsx("li",{children:e.jsx("div",{className:"Survey__question",children:e.jsxs("div",{className:"Survey__questionHeader",children:[e.jsx("div",{className:"Survey__answer",children:e.jsx(v.Item,{onChange:p=>{a.text=p.target.value},name:a.id,rules:g,initialValue:a.text,children:e.jsxs("div",{className:"fake-input",children:[e.jsx("span",{className:"fake-radio-button"}),e.jsx(j,{defaultValue:a.text,placeholder:u("surveys.variant")+" "+ ++t})]})})}),e.jsx("div",{style:{cursor:"pointer",zIndex:"777"},onClick:()=>i(r,--t),children:e.jsx(K,{})})]})})},a.id))});if(s===x[3].id)return e.jsx(e.Fragment,{children:r.options.payload.choices.map((a,t)=>e.jsx("li",{children:e.jsx("div",{className:"Survey__question",children:e.jsxs("div",{className:"Survey__questionHeader",children:[e.jsx("div",{className:"Survey__answer",children:e.jsx(v.Item,{onChange:p=>{a.text=p.target.value},name:a.id,rules:g,initialValue:a.text,children:e.jsxs("div",{className:"fake-input",children:[e.jsx("span",{className:"fake-checkbox-button"}),e.jsx(j,{defaultValue:a.text,placeholder:u("surveys.variant")+" "+ ++t})]})})}),e.jsx("div",{style:{cursor:"pointer",zIndex:"777"},onClick:()=>i(r,--t),children:e.jsx(K,{})})]})})},a.id))})},b=(s,r)=>{const a=[...n],t=n.indexOf(r);a[t].type=s,(s===x[0].id||s===x[1].id)&&(a[t].options={kind:s,payload:{minlength:0}}),(s===x[2].id||s===x[3].id)&&(a[t].options={kind:s,payload:{choices:r.options.payload.choices?[...r.options.payload.choices]:[{id:S(),text:"",description:""}]}}),l.setFieldsValue({questions:[...a]}),d(a)},_=(s,r)=>{const a=[...n],t=n.indexOf(r);a[t]={...a[t],is_required:s,was_changed:!0},l.setFieldsValue({questions:[...a]}),d(a)},y=()=>{const s=[...n];s.push({id:S(),type:2,name:"",is_required:!0,options:{kind:x[2].id,payload:{choices:[{id:S(),text:"",description:""}]}}}),l.setFieldsValue({questions:[...s]}),d(s)},f=s=>{const r=[...n],a=n.indexOf(s);r[a].options.payload.choices.push({id:S(),text:"",description:""}),l.setFieldsValue({questions:[...r]}),d(r)},i=(s,r)=>{const a=[...n],t=n.indexOf(s);a[t].options.payload.choices.length>1&&(a[t].options.payload.choices.splice(r,1),l.setFieldsValue({questions:[...a]}),d(a))},h=s=>{const r=structuredClone(s),a=[...n];r.id=S(),(s.type===x[2].id||s.type===x[3].id)&&r.options.payload.choices.forEac
1h(t=>{t.id=S()}),a.push(r),l.setFieldsValue({questions:[...a]}),d(a)},o=s=>{if(n.length>1){const r=[...n],a=n.indexOf(s);r.splice(a,1),l.setFieldsValue({questions:[...r]}),d(r)}};return e.jsxs(e.Fragment,{children:[e.jsxs(w,{type:"white",className:"Survey__card Survey__card_header",children:[e.jsx(v.Item,{rules:g,name:"name",className:"Survey__card-title",children:e.jsx(j,{})}),e.jsx(F,{}),e.jsx(v.Item,{rules:g,name:"description",className:"Survey__card-description",children:e.jsx(j,{})})]}),e.jsx(w,{type:"white",className:"Survey__card Survey__card_date-pick flex fl-align-end",children:e.jsx(v.Item,{className:"mr-4",rules:g,label:u("surveys.user.allowed_attempts"),name:"attempts_allowed",children:e.jsx(j,{type:"number"})})}),e.jsx("ul",{className:"Survey__questionList",children:n==null?void 0:n.map((s,r)=>{var a;return e.jsx("li",{children:e.jsxs(w,{type:"white",className:"Survey__card",children:[e.jsxs("div",{className:"Survey__questionHeader",children:[e.jsx(v.Item,{onChange:t=>{s.name=t.target.value},name:s.id,rules:g,initialValue:s.name||"",children:e.jsx(j,{placeholder:u("base.question")+" "+r++})}),e.jsx(P,{onChange:t=>b(t,s),defaultValue:x[2].id,children:(a=x)==null?void 0:a.map(t=>e.jsx(P.Option,{value:t.id,children:t.name},t.id))})]}),e.jsxs("ul",{className:"Survey__subQuestionList",children:[e.jsx(v.Item,{onChange:t=>{s.description=t.target.value},name:s.description,rules:g,initialValue:s.description||"",children:e.jsx(j,{placeholder:u("base.description")})}),c(s.type,s)]}),s.type!==0&&s.type!==1?e.jsx(Q,{onClick:()=>f(s),type:"default",icon:e.jsx(H,{}),children:u("surveys.add_question_variant")}):e.jsx(e.Fragment,{}),e.jsx(F,{}),e.jsxs("div",{className:"Survey__questionFooter",children:[e.jsx(re,{onClick:()=>h(s),style:{fontSize:"18px"}}),e.jsx(ne,{onClick:()=>o(s),style:{fontSize:"18px"}}),e.jsx(F,{type:"vertical"}),e.jsxs(v.Item,{valuePropName:"is_answer_required",style:{marginBottom:0,color:"rgba(36, 34, 32, 0.4)"},children:[u("base.required_question"),e.jsx(Y,{checkedChildren:u("base.yes"),unCheckedChildren:u("base.no"),checked:s.is_required,onChange:t=>_(t,s)})]})]})]})},s.id)})}),e.jsx(Q,{className:"Survey__add-question",onClick:y,type:"default",icon:e.jsx(H,{})})]})},Se={plugins:{legend:{position:"right"}}},Ne={indexAxis:"y",scales:{x:{ticks:{stepSize:1}}},responsive:!0,plugins:{legend:{display:!1}}},we={responsive:!0,plugins:{legend:{display:!1},title:{display:!1}},scales:{y:{ticks:{stepSize:1}}}};ce.register(oe,de,ue,pe,me,xe,he);const Ce=({surveyId:l,survey:n,questions:d,isFinished:u})=>{const{t:c}=$(),b=l!==null,{data:_}=O({queryKey:["results"],queryFn:()=>je(l),enabled:b&&u,onError:()=>{E("error",c("base.error_on_load"))}}),{data:y}=O({queryKey:["participants"],queryFn:()=>fe(l),enabled:b,onError:()=>{E("error",c("base.error_on_load"))}}),f=(i,h)=>{const o=h==null?void 0:h.filter(s=>s.question_id===i.id);if((i==null?void 0:i.type)===q)return e.jsx("div",{className:"Survey__answers-container",children:o==null?void 0:o.map(s=>e.jsx("div",{className:"Survey__answer-wrapper",children:e.jsx("p",{children:s.value})},s.id))});if((i==null?void 0:i.type)===ee)return e.jsx("div",{className:"Survey__answers-container",children:o==null?void 0:o.map(s=>e.jsx("div",{className:"Survey__answer-wrapper",children:e.jsx("p",{children:s.value})},s.id))});if((i==null?void 0:i.type)===se){const s=i.options.payload.choices,r=s==null?void 0:s.map(t=>o==null?void 0:o.filter(p=>t.text===p.value).length),a={labels:s==null?void 0:s.map(t=>t.text),datasets:[{label:"# of Votes",data:r,backgroundColor:["rgba(66, 133, 244, 1)","rgba(219, 68, 55, 1)","rgba(244, 180, 0, 1)","rgba(15, 157, 88, 1)"],borderColor:["rgba(255, 255, 255, 1)"],borderWidth:1}]};return e.jsx("div",{className:"Survey__chart flex fl-justify-content-center",children:e.jsx(le,{options:Se,data:a,className:"Survey__pie-chart"})})}if((i==null?void 0:i.type)===ae){const s=i.options.payload.choices,r=[];o==null||o.forEach(p=>{p.value!==null&&r.push(...p.value.split(", "))});const a=s==null?void 0:s.map(p=>r==null?void 0:r.filter(N=>p.text===N).length),t={labels:s==null?void 0:s.map(p=>p.text),datasets:[{label:"",data:a,borderColor:"rgba(66, 133, 244, 1)",backgroundColor:"rgba(66, 133, 244, 1)"}]};return e.jsx("div",{className:"Survey__chart flex fl-justify-content-center",children:e.jsx(U,{options:Ne,data:t})})}if((i==null?void 0:i.type)===te){const{min:s,max:r,step:a}=i.options.payload,t=J(s,r,a),p=R=>
1o==null?void 0:o.filter(m=>Number(m.value)===R).length,N={labels:t,datasets:[{data:t.map(p),borderColor:"rgba(24, 144, 255, 1)",backgroundColor:"rgba(24, 144, 255, 1)"}]};return e.jsxs("div",{className:"Survey__chart flex fl-justify-content-center",children:[e.jsx(U,{options:we,data:N}),";"]})}};return e.jsxs(e.Fragment,{children:[e.jsxs(w,{type:"white",className:"Survey__card Survey__card_header",children:[e.jsx("div",{className:"Survey__card-title",children:e.jsx("h1",{children:n==null?void 0:n.name})}),e.jsx(F,{}),e.jsxs("div",{className:"Survey__card-description",children:[e.jsxs("p",{children:[c("surveys.attempts_per_user")," ",n==null?void 0:n.attempts_allowed]}),e.jsxs("p",{children:[c("surveys.participants_number")," ",y==null?void 0:y.total_people_invited]}),e.jsxs("p",{children:[c("surveys.completed_survey")," ",y==null?void 0:y.total_participants]})]})]}),e.jsx("ul",{className:"Survey__questionList",children:u&&(d==null?void 0:d.map((i,h)=>e.jsx("li",{children:e.jsxs(w,{type:"white",className:"Survey__card",children:[e.jsx("div",{className:"Survey__questionHeader",children:e.jsxs("h2",{children:[h+1,". ",i.name]})}),e.jsx("ul",{className:"Survey__subQuestionList",children:f(i,_)})]})},i.id)))})]})},Ze=()=>{const{uid:l,tab:n}=M(),[d,u]=A.useState(Number(n)),[c,b]=A.useState(null),[_,y]=A.useState([]),[f]=v.useForm(),{t:i}=$(),h=W(),o=ve(),s=[{label:i("surveys.segmented.edit"),value:0,disabled:(c==null?void 0:c.start_at)!==null},{label:i("surveys.segmented.preview"),value:1},{label:i("surveys.segmented.results"),value:2,disabled:(c==null?void 0:c.start_at)===null}],r=()=>o.invalidateQueries({queryKey:["surveys"]}),{isFetching:a}=O({queryKey:["survey"],queryFn:()=>X(l),enabled:l!==null,onSuccess:m=>{if(m){const T=structuredClone(m.questions.sort((z,C)=>z.position-C.position));b(m),y(T),f.setFieldsValue({name:m.name,description:m.description,attempts_allowed:m.attempts_allowed,questions:_})}},onError:()=>{E("error",i("base.error_on_load"))}}),{mutate:t}=ye({mutationFn:_e,onSuccess:()=>{r(),E("success",i("surveys.successfully_updated")),h(I)}}),p=({name:m,description:T,attempts_allowed:z})=>{const C={name:m,description:T,attempts_allowed:Number(z)},D=B(C,{name:c.name,description:c.description,attempts_allowed:c.attempts_allowed})?null:C,L=B(_,c.questions)?null:_;if(D||L)return t({surveyId:l,surveyInfo:D,questions:{questions_data:L}});h(I)},N=()=>d===1?e.jsx(ie,{form:f,questions:_}):d===2?e.jsx(Ce,{survey:c,questions:_,surveyId:l,isFinished:G().isAfter(c==null?void 0:c.close_at)}):e.jsx(be,{form:f,questions:_,setQuestions:y}),R=m=>{u(m),h(`${I}/${l}/${m}`)};return a?e.jsxs("div",{className:"Survey__skeleton",children:[e.jsx(k.Input,{className:"mb-4",active:!0,size:"large",block:!0}),e.jsx(k.Input,{className:"mb-4",active:!0,size:"large",block:!0}),e.jsx(k.Input,{className:"mb-4",active:!0,size:"large",block:!0}),e.jsx(k.Input,{active:!0,size:"large",block:!0})]}):e.jsx("div",{className:"Survey",children:e.jsxs(v,{form:f,onFinish:d===0?p:()=>h(I),layout:"vertical",children:[e.jsxs("div",{className:"Survey__nav mb-3 flex fl-justify-content-between fl-align-start",children:[e.jsx(Z,{onChange:R,options:s,defaultValue:Number(n)}),e.jsx(Q,{type:"primary",htmlType:"submit",children:i("surveys.finish")})]}),e.jsx("div",{className:"Survey",children:N()})]})})};export{Ze 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.