1import{j as e,r as a}from"./react-vendor.B75MsAI9.js";import{Q as n,T as s,a4 as t,u as r,t as i,p as l,cw as o,at as c,av as d,cz as u,e5 as m,e6 as g,H as h,e7 as p,C as x,e8 as b,e9 as _,M as j,az as v,cr as F,aA as y,o as f,d9 as C}from"./AuthModalContainer.D3JsQqnf.js";/* empty css */const N=({id:a,error:t,onChange:r,ratio:i="1-by-1",defaultValue:l,value:o,inlineLabel:c,disabled:d})=>{const u="pb-inline-textfield",m={[u]:!0,[`${u}--${i}`]:i},g={[`${u}__label`]:!0,[`${u}__label--error`]:t};return e.jsx("div",{className:n(m),children:e.jsxs("div",{className:`${u}__text-field-wrapper`,children:[e.jsx("span",{className:n(g),children:c}),e.jsx("div",{className:`${u}__text`,children:e.jsx(s,{id:a,error:t,value:o,defaultValue:l,onChange:r,disabled:d})})]})})};N.propTypes={ratio:t.oneOf(["1-by-1","1-by-3","3-by-1"]),id:t.string,error:t.string,onChange:t.func,defaultValue:t.string,value:t.string,inlineLabel:t.string,disabled:t.bool};const G="pb-gating-form",$=["1-5","6-10","11-20","21-50","50+"],k=["Teacher","Parent / Caregiver","Student","Librarian / Storyteller","NGO / Non-profit organisation","School / Institution","Publisher","Ed-tech / Platform","Other"],S=["For individual/home use for the children in my family","For organizing reading sessions / reading clubs in the community","For use in classrooms","For creating assessments","For creating teacher development / training aides","For inclusion in lesson plans","For inclusion in textbooks","For publishing on an app","For publishing on another platform"],w="For reading in classroom / school",O="For reading at home",P="For printing for distribution",T="For printing for home use",U="For including in textbooks",L="For including in lesson plans/ creating assessments",I="For teacher training / capacity building",V="For publishing on an app / platform",A="For translation / adaptation",M=[w,O,P,T,U,L,I,V,A],R={Teacher:[w,L,I,A],"Parent / Caregiver":[O,T,A],Student:[w,O,T,A],"Librarian / Storyteller":[w,O,T,A],"NGO / Non-profit organisation":[P,L,I,V,A],"School / Institution":[w,P,U,L,I,V,A],Publisher:[P,U,V,A],"Ed-tech / Platform":[w,P,U,L,I,V,A],Other:M},q=({userType:a,onUserTypeChange:n,viewport:s,t:t})=>e.jsx(C,{id:"gating-form-user-type",radios:[{label:t("GatingForm.label-reader"),value:o.individualUser},{label:t("GatingForm.label-work-with-organisation"),value:o.edOrg},{label:t("GatingForm.label-work-with-ed-tech"),value:o.edTech}],defaultValue:a,viewport:s,onChange:n,name:"gating-form-user-type",theme:"black",inlineRadio:s.medium}),B=({parentClassName:t,isVisible:C,viewport:w,showImageGatingForm:O,showStoryGatingForm:P,showStoryGatingFormPdf:T,user:U,organisation:L,imageId:I,storyId:V,format:A})=>{const B=r(),E=i(),z=l(e=>e.book.isUploadingGatingForm),[K,D]=a.useState([]),[H,Q]=a.useState(""),[W,J]=a.useState(!1),[X,Y]=a.useState(o.individualUser),[Z,ee]=a.useState(!1),[ae,ne]=a.useState(""),[se,te]=a.useState(""),[re,ie]=a.useState(L||"NA"),[le,oe]=a.useState("story"),[ce,de]=a.useState(""),[ue,me]=a.useState(""),[ge,he]=a.useState(""),[pe,xe]=a.useState(""),[be,_e]=a.useState(""),[je,ve]=a.useState(""),[Fe,ye]=a.useState(""),[fe,Ce]=a.useState(""),[Ne,Ge]=a.useState([]),[$e,ke]=a.useState(""),[Se,we]=a.useState(!1),Oe=l(e=>{var a;return null==(a=e.gatingForm)?void 0:a.languageOptions})||[],Pe=l(e=>{var a;return null==(a=e.gatingForm)?void 0:a.isFetchingLanguageOptions}),Te=P||T,Ue=O||Te,Le=X===o.edOrg||X===o.edTech;a.useEffect(()=>{ie(L||"NA")},[L]),a.useEffect(()=>{Te&&C&&(E(c()),J(!1),Q(""))},[Te,C,E]);const Ie=d(()=>{Se&&we(!1)},Se),Ve=a.useMemo(()=>Ne.length?Ne.map(e=>{const a=Oe.find(a=>a.queryValue===e);return a?a.name:e}).join(", "):B("GatingForm.select-languages-placeholder"),[Ne,Oe,B]),Ae=a.useCallback(e=>0!==e.length&&/^\d*$/.test(e),[]),Me=a.useCallback(e=>!!e.trim().length,[]),Re=a.useCallback(e=>/^\d*$/.test(e)&&parseInt(e,10)>0,[]),qe=a.useCallback(e=>Array.isArray(e)&&e.length>0,[]),Be=a.useCallback(()=>{let e=Te?K.length>0||Me(be):K.length>0||W;Ue||(ae.length>0&&(e=e&&Ae(ae)),se.length>0&&(e=e&&Ae(se))),W&&!Te&&(e=e&&H.length>0&&Me(H)),O&&(e=e&&ce.length>0&&Re(ce)),Te&&(e=e&&ue.length>0,pe.length>0&&(e=e&&Re(pe)),e=e&&Fe.length>0,"Other"===Fe&&(e=e&&Me(fe)),e=e&&qe(Ne)),ee(!!e)},[K,Ue,ae,se,W,H,O,ce,Te,ue,be,je,pe,Fe,fe,Ne,Ae,Me,Re,qe]);a.useEffect(()=>{Be()},[Be]);const Ee=a.useCallback(e=>{Y(e),D([]),Q(""),J(!1),ne(""),te(""),ie(L||"NA")},[L]),ze=a.useCallback(({checked:e,value:a})=>{D(e?e=>[...e,a]:e=>e.filter(e=>e!==a))},[]),Ke=a.useCallback(e=>{J(e.checked)},[]),De=a.useCallback((e,a)=>{const n=a.target.value;"childrenCount"===e?ne(n):"schoolCount"===e?te(n):"imageCount"===e?de(n):"otherReason"===e?Q(n):"scaleOrganisationName"===e?he(n):"scaleUsersCount"===e?xe(n):"reasonNotListed"===e?_e(n):"additionalInfo"===e?ve(n):"assessmentUserTypeOther"===e&&Ce(n)},[]),He=a.useCallback(e=>{ie(e.target.value)},[]),Qe=a.useCallback((e,a)=>{Ge(n=>a?n.includes(e)?n:[...n,e]:n.filter(a=>a!==e))},[]),We=a.useCallback(e=>{e.charCode===u.return&&Z&&(e.preventDefault(),e.stopPropagation())},[Z]),Je=a.useCallback(()=>{E(m())},[E]),Xe=a.useCallback(async()=>{let e=K;W&&(e=K.concat(H));const a={user_type:X,download_reasons:e,children_count:ae,schools_count:se,updated_organisation:re,feedback_type:le};try{const e=await E(g({postGatingFormPayload:a}));Je(),e.ok?E(h({type:"success",content:B("GatingForm.details-added-success")})):E(h({type:"danger",content:e&&e.data&&e.data.errorMessage}))}catch(n){E(h({type:"danger",content:n.message||"An error occurred"}))}}
1,[K,W,H,X,ae,se,re,le,E,Je,B]),Ye=a.useCallback(async()=>{let e=K;W&&!Te&&(e=K.concat(H));let a=Fe;"Other"===Fe&&Me(fe)&&(a=Fe.concat(",",fe));const n={download_type:Te?"story":"illustration",format:A,requestable_format:Te?T?"pdf":"epub":null,id:Te?V:I,reason:e,download_count:Te?ue:ce,scale_organisation_name:Te&&ge.trim()||null,scale_users_count:Te&&pe.trim()||null,reason_not_listed:Te&&be.trim()||null,additional_info:Te&&je.trim()||null,assessment_user_type:Te?a:null,preferred_languages:Te?Ne:[]};try{const e=await E(p({postGatingFormPayload:n}));e.ok?(Je(),E(h({type:"success",content:B(Te?"GatingForm.story-response-recorded":"GatingForm.details-added-success")}))):E(h({type:"danger",content:e&&e.data&&e.data.errorMessage}))}catch(s){E(h({type:"danger",content:s.message||"An error occurred"}))}},[K,W,H,Fe,fe,Me,Te,A,T,V,I,ce,ue,ge,pe,be,je,Ne,E,Je,B]),Ze={[G]:!0,[t]:t,[`${G}--image`]:Ue},ea={[`${G}__title`]:!0},aa=(a,n="")=>Te?e.jsx("span",{className:`${G}__q-num`,children:`${a}${n}.`}):null;if(!C)return null;const na=a.useMemo(()=>O?S:Te?Fe?R[Fe]||M:[]:X===o.individualUser?[B("GatingForm.reason-for-children"),B("GatingForm.reason-for-organisation"),B("GatingForm.reason-for-translation")]:X===o.edOrg?[B("GatingForm.reason-for-classroom"),B("GatingForm.reason-for-training-programs")]:[B("GatingForm.reason-for-publishing-on-plateform"),B("GatingForm.reason-for-publishing-on-app"),B("GatingForm.reason-for-assessment"),B("GatingForm.reason-for-textbooks"),B("GatingForm.reason-for-lesson-plans"),B("GatingForm.reason-for-printing")],[O,Te,X,Fe,B]).map(a=>e.jsx("div",{className:`${G}__checkbox-wrapper`,children:e.jsx(x,{label:a,name:`GatingForm-checkbox-${a}`,value:a,inline:!0,onChange:ze,checked:K.includes(a),theme:K.includes(a)?null:"grey",themeLabel:K.includes(a)?"black":null})},a)),sa=Te?e.jsxs("div",{children:[e.jsx("hr",{}),e.jsxs("div",{className:n(ea),children:[aa(1),B("GatingForm.assessment-user-title"),e.jsx("span",{className:`${G}__mandatory-marker`,children:"*"})]}),e.jsxs("div",{style:{marginBottom:"10px"},children:["(",B("GatingForm.select-one"),")"]}),e.jsxs("div",{className:`${G}__radio-group`,children:[k.map(a=>e.jsxs("label",{className:`${G}__radio-option`,children:[e.jsx("input",{type:"radio",name:"gating-form-assessment-user-type",value:a,checked:Fe===a,onChange:e=>{ye(e.target.value),D([]),J(!1),Q("")},className:`${G}__radio-input`}),e.jsx("span",{children:a})]},a)),"Other"===Fe?e.jsx("div",{className:`${G}__other-textbox`,children:e.jsx(s,{id:"gating-form-assessment-user-type-other",name:"assessmentUserTypeOther",value:fe,onChange:e=>De("assessmentUserTypeOther",e),label:"Other:",error:b(fe,B),autoFocus:!0})}):null]})]}):null,ta=X===o.individualUser?B("GatingForm.children-count"):B("GatingForm.other-children-count"),ra=B(Te?"GatingForm.story-text":O?"GatingForm.illustration-text":"GatingForm.text"),ia=Te?e.jsxs(a.Fragment,{children:[aa(2,"a"),B("GatingForm.story-reason-title"),0===K.length&&Me(be)?null:e.jsx("span",{className:`${G}__mandatory-marker`,children:"*"})]}):B(O?"GatingForm.illustration-reason-title":"GatingForm.reason-title"),la=e=>{let a="";return/^\d*$/.test(e)||(a=B("Validation.is-numeric")),parseInt(e,10)<=0&&(a=B("Validation.is-greater-than",0)),a};let oa=e.jsx(N,{id:"gating-form-children-count",name:"childrenCount",value:ae,onChange:e=>De("childrenCount",e),ratio:"3-by-1",inlineLabel:ta,error:ae?_(ae,B):null});O&&(oa=w.medium?e.jsx(N,{id:"gating-form-image-count",name:"imageCount",value:ce,onChange:e=>De("imageCount",e),ratio:"3-by-1",inlineLabel:B("GatingForm.illustration-count-label"),error:ce?la(ce):""}):e.jsxs("div",{children:[e.jsx("div",{className:`${G}__text-field-label`,children:B("GatingForm.illustration-count-label")}),e.jsx(s,{id:"gating-form-image-count",name:"imageCount",value:ce,onChange:e=>De("imageCount",e),error:ce?la(ce):"",parentClassName:`${G}__count`})]})),Te&&(oa=e.jsxs("div",{children:[e.jsxs("div",{className:n(ea),children:[aa(3),B("GatingForm.story-count-label"),e.jsx("span",{className:`${G}__mandatory-marker`,children:"*"})]}),e.jsxs("div",{style:{marginBottom:"10px"},children:["(",B("GatingForm.select-one"),")"]}),e.jsx("div",{className:`${G}__radio-group`,children:$.map(a=>e.jsxs("label",{className:`${G}__radio-option`,children:[e.jsx("input",{type:"radio",name:"gating-form-story-count-range",value:a,checked:ue===a,onChange:e=>me(e.target.value),className:`${G}__radio-input`}),e.jsx("span",{children:a})]},a))})]}));const ca=Te?e.jsxs("div",{children:[e.jsx("hr",{}),e.jsxs("div",{className:n(ea),children:[aa(5),B("GatingForm.scale-usage-title")]}),e.jsx("div",{className:`${G}__scale-field`,children:e.jsx(s,{id:"gating-form-scale-organisation-name",name:"scaleOrganisationName",value:ge,onChange:e=>De("scaleOrganisationName",e),label:B("GatingForm.scale-organisation-name")})}),e.jsx("div",{className:`${G}__scale-field`,children:e.jsx(s,{id:"gating-form-scale-users-count",name:"scaleUsersCount",value:pe,onCh
1ange:e=>De("scaleUsersCount",e),label:B("GatingForm.scale-users-count"),error:pe?la(pe):""})})]}):null,da=Te?e.jsxs("div",{className:`${G}__story-reason-not-listed`,children:[e.jsxs("div",{className:n(ea),children:[aa(2,"b"),B("GatingForm.story-reason-not-listed-title"),K.length?null:e.jsx("span",{className:`${G}__mandatory-marker`,children:"*"})]}),e.jsx(s,{id:"gating-form-reason-not-listed",name:"reasonNotListed",type:"multiline",onKeyPress:We,value:be,onChange:e=>De("reasonNotListed",e),error:K.length?null:b(be,B)})]}):null,ua=Te?e.jsxs("div",{children:[e.jsx("hr",{}),e.jsxs("div",{className:n(ea),children:[aa(6),B("GatingForm.download-books-purpose-title")]}),e.jsxs("div",{style:{marginBottom:"10px"},children:["(",B("GatingForm.short-answer"),")"]}),e.jsx(s,{id:"gating-form-additional-info",name:"additionalInfo",type:"multiline",onKeyPress:We,value:je,onChange:e=>De("additionalInfo",e),error:null})]}):null;return e.jsx("div",{className:n(Ze),children:e.jsx(j,{onClose:Je,parentClassName:`${G}__modal-wrapper`,children:e.jsxs("form",{className:`${G}__form`,onKeyPress:We,children:[e.jsx("h1",{className:`${G}__header-title`,children:B(Ue?"GatingForm.illustration-title":"GatingForm.title")}),e.jsxs("div",{className:`${G}__form-body`,children:[e.jsxs("div",{className:`${G}__description`,children:[e.jsx("p",{children:Ue?`${B("GatingForm.salutation")} ${U.first_name} ${U.last_name},`:null}),e.jsx("p",{children:ra})]}),sa,Ue?null:e.jsx("div",{className:n(ea),children:B("GatingForm.user-title")}),Ue?null:e.jsx(q,{userType:X,onUserTypeChange:Ee,viewport:w,t:B}),e.jsxs("div",{children:[X!==o.individualUser?e.jsxs("div",{children:[Le?e.jsx(N,{id:"gating-form-organisation",name:"organisation",onChange:He,defaultValue:re,inlineLabel:B("GatingForm.organisation"),ratio:"1-by-3"}):null,e.jsx("div",{className:`${G}__edit-dashboard-link`,children:B("GatingForm.edit-detail-text")})]}):null,O&&!w.medium||Te?e.jsx("hr",{}):null,e.jsx("div",{className:n(ea),children:ia}),Te?e.jsxs("div",{style:{marginBottom:"10px"},children:["(",B("GatingForm.select-all"),")"]}):null,O&&w.medium?e.jsx("hr",{}):null]}),e.jsxs("div",{className:`${G}__radio-group`,children:[na,Te||Le?null:e.jsx("div",{className:`${G}__checkbox-wrapper`,children:e.jsx(x,{id:"other",label:B("GatingForm.reason-other"),inline:!0,onChange:Ke,checked:W,theme:W?null:"grey",themeLabel:W?"black":null})}),!0!==W||Te||X===o.edTech||X===o.edOrg?null:e.jsx("div",{className:`${G}__other-textbox`,children:e.jsx(s,{id:"gating-form-other-reason",name:"otherReason",type:"multiline",onKeyPress:We,value:H,onChange:e=>De("otherReason",e),label:B("GatingForm.other-reason-label"),error:b(H,B),autoFocus:!0})})]}),da,Ue?e.jsx("hr",{}):null,e.jsxs("div",{className:`${G}__bottom-wrapper`,children:[oa,X!==o.individualUser?e.jsx(N,{id:"gating-form-school-count",name:"schoolCount",value:se,onChange:e=>De("schoolCount",e),inlineLabel:B("GatingForm.school-count"),ratio:"3-by-1",error:se?_(se,B):null}):null]}),e.jsxs("div",{children:[Te?e.jsx("hr",{}):null,Te?e.jsxs(a.Fragment,{children:[e.jsxs("div",{className:n(ea),children:[aa(4),B("GatingForm.story-languages"),e.jsx("span",{className:`${G}__mandatory-marker`,children:"*"})]}),e.jsxs("div",{style:{marginBottom:"10px"},children:["(",B("GatingForm.select-all"),")"]})]}):null,Te?e.jsxs("div",{ref:Ie,className:`${G}__language-picker`,children:[e.jsxs("button",{type:"button",className:`${G}__language-picker-control`,onClick:()=>we(e=>!e),"aria-expanded":Se,"aria-haspopup":"listbox",children:[e.jsx("span",{className:n({[`${G}__language-picker-placeholder`]:!Ne.length}),children:Ve}),e.jsx(v,{parentClassName:`${G}__language-picker-caret`,direction:"down"})]}),Se?e.jsx("div",{className:`${G}__language-picker-list`,children:Pe&&!Oe.length?e.jsx(F,{size:"m"}):e.jsx(y,{id:"gating-form-languages",options:Oe,checkedValues:Ne,onChange:Qe,searchValue:$e,onSearchChange:e=>ke(e.target.value),multiplePicks:!0,searchFilterByName:!0,exactMatch:!0,autoFocus:!0})}):null]}):null]}),ca,ua,Ue?null:e.jsx("div",{className:`${G}__notice`,children:B("GatingForm.licence-text").trim()}),O&&!w.medium?e.jsx("hr",{}):null,e.jsx("div",{className:`${G}__cta-wrapper`,children:e.jsx(f,{variant:"primary",disabled:!Z,fullWidth:!0,label:B("global.submit"),loading:z,onClick:()=>{Ue?Ye():Xe()}})})]})]})})})};
1B.propTypes={parentClassName:t.string,isVisible:t.bool.isRequired,viewport:t.object.isRequired,showImageGatingForm:t.bool,showStoryGatingForm:t.bool,showStoryGatingFormPdf:t.bool,user:t.object.isRequired,organisation:t.string,imageId:t.string,storyId:t.string,format:t.string};export{B 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.