import{o as u}from"./orderBy-DbTWENOv.js";import{r as o,c,a as m,u as p,e as h}from"./validators-NQYIHf-w.js";import{V as d,W as _}from"./setup-BuwH6Opq.js";import{g}from"./index-CEZspPmZ.js";import{i as y}from"./people-CVQSZXqA.js";function F(){return{beforeFormInit(){this.initFields()},data(){return{fieldsProcessed:[],fieldsMap:{},isConsentsRequired:!0,maxSelectedSessions:5}},computed:{fieldsSorted(){return u(this.fieldsProcessed,"position")},generalFields(){return this.fieldsSorted.filter(e=>e.type!=="consent")},baseFields(){return this.isEmailOptional?this.fields.filter(e=>["email","first_name","last_name"].includes(e.slug)):null},fieldsWhenEmailOptional(){return["form_light","form_lobby"].includes(this.registrationType)||!this.isEmailOptional?this.generalFields:this.generalFields.filter(e=>!["email","first_name","last_name"].includes(e.slug))},isEmailOptional(){return!this.fields.find(e=>e.slug==="email"&&e.required)},isEmailDisabled(){return!this.fields.some(e=>e.slug==="email")},consentFields(){return this.fieldsSorted.filter(e=>e.type==="consent")},registerSomeoneConsent(){return{id:"__register_someone_consent__",slug:"__register_someone_consent__",value:!1,type:"consent",required:!0,label:this.i18n.t("dashboard_sidepane-register-someone_consent"),position:101,tooltip:null,inputType:"checkbox"}},livestormConsent(){return{id:"__livestorm_consent__",slug:"__livestorm_consent__",value:!1,type:"consent",required:this.isConsentsRequired,label:this.i18n.t("general_consent-terms-registrant"),position:100,tooltip:this.i18n.t("general_more-info"),inputType:"checkbox"}},canBeAutoSubmitWithOAuth(){return this.fields.filter(e=>!["first_name","last_name","email"].includes(e.slug)).length===0},selectedSessionsLabel(){var e,r,s,i;if(((e=this.selectedSessionsArray)==null?void 0:e.length)===1){if(!this.sessionData)return"";const n=this.formatSessionDate(this.sessionData),t=((r=this.eventTypeData)==null?void 0:r.title)||((s=this.eventType)==null?void 0:s.title),l=this.sessionData.name!==t?` - ${this.sessionData.name}`:"";return`${n}${l}`}return(i=this.selectedSessionsArray)!=null&&i.length?this.i18n.t("registration_sessions-selected-label",{count:this.selectedSessionsArray.length}):this.i18n.t("registration_no-sessions-selected-label")},maxSelectedSessionsReached(){var e;return((e=this.selectedSessionsArray)==null?void 0:e.length)>this.maxSelectedSessions},noSelectedSessions(){var e;return((e=this.selectedSessionsArray)==null?void 0:e.length)===0}},validations(){var e;return{formInputData:{selectedSessions:{required:o},...(e=this.fieldsProcessed)==null?void 0:e.reduce((r,s)=>{const i=r[s.slug]={};return this.expandAllFields&&(s.type==="consent"&&s.required?i.checked=c:s.required&&(s.slug==="avatar"?i.required=m:i.required=o),s.type==="url"&&(i.url=p)),s.slug==="email"&&(i.email=h,this.isEmailOptional||(i.required=o)),r},{})}}},methods:{initFields(){const e={},r=this.isConsentsRequired?[this.livestormConsent]:[];this.showRegisterSomeoneConsent&&r.push(this.registerSomeoneConsent);const i=this.fields.concat(r).map(n=>{const t={...n};return e[n.slug]=null,n.type==="unique_select"?t.inputType="select":n.type==="multiple_select"?(t.inputType="select",t.multi=!0):n.type==="consent"?t.inputType="checkbox":t.inputType="text",this.googleAuth&&n.slug==="email"&&(t.disabled=!0),this.fieldsMap[t.id]=t,t});this.fieldsProcessed=i,this.initialData=e},updateConsentsRequired(e){this.isConsentsRequired=e,this.fieldsProcessed.find(r=>r.type==="consent").required=e,this.fieldsMap.__livestorm_consent__.required=e},shouldCheckEmail(e){return!this.isEmailOptional||e&&!y(e)},async processMainData(e){await d();const r=this.fields.map(n=>{let t=e[n.slug];return(!t||n.slug==="avatar")&&(n.options&&n.type==="multiple_select"?t=[""]:t=""),{id:n.id,slug:n.slug,value:t}}),s=!!e.avatar,i={event_type_id:this.eventTypeId,session_id:this.currentSessionId||e.sessionId,[s?"people_attributes_string":"people_attributes"]:r,[s?"fields_string":"fields"]:this.processLegacyFieldsData(e),email:e.email,[s?"timezone_string":"timezone"]:_(),terms_participant_checked:this.isConsentsRequired,terms_participant_text:this.isConsentsRequired?`${this.i18n.t("general_consent-terms-registrant")} *`:null,avatar:e.avatar,kickbox:this.shouldCheckEmail(e.email)&&await g(e.email),registration_type:this.registrationType};return this.formAvatarUrl&&(i.remote_avatar_url=this.formAvatarUrl),i},processLegacyFieldsData(e){return this.fields.map(s=>{var l;let i=e[s.slug];(!i||s.slug==="avatar")&&(s.options&&s.type==="multiple_select"?i=[""]:i="");let n="text";s.type==="unique_select"||s.type==="multiple_select"?n="multiple":s.type==="consent"&&(n="consent");let t=null;return s.options.length&&(t={items:(l=s.options)==null?void 0:l.map(a=>({text:a.label,value:""})),multiple_answers:s.type==="multiple_select"}),s.type==="consent"&&(t={text:s.label}),{checked:!0,id:s.slug,label:s.builtin?this.i18n.t(`general_form_${s.slug}`):s.name,order:s.position,required:s.required,value:i,custom:!s.builtin,disabled:!1,type:n,options:t}})}}}}export{F};