1import{a as h}from"./chunk-KGJ2ZQVY.js";import{a as S}from"./chunk-NXJNUPQ3.js";import{t as b}from"./chunk-KF3EAUWK.js";import{a as l,b as p,ba as F,ga as d}from"./chunk-33WATMYR.js";var m=class o{static fieldsIconsMap={name:"person",phone:"call",date:"",email:"mail",textarea:"",banAddress:"location_on",address:"location_on",picture:"photo_camera",document:"upload_file",list:"format_list_bulleted",multilist:"check_box",number:"tag",text:"text_fields"};static mapToDynamicFormFields(e){return e.map(t=>({extraData:t.extraData,isFilterable:t.isFilterable,isMandatory:t.isMandatory,label:t.label,name:t.name,preview:t.preview,type:t.type,values:t.values}))}static mapToFormFields(e){return e.map(t=>{let r={extraData:t.extraData,isFilterable:t.isFilterable,isMandatory:t.isMandatory,label:t.label,name:t.name,preview:t.preview,type:t.type,values:t.values,icon:o.fieldsIconsMap[t.name]??o.fieldsIconsMap[t.type]??"",availableAppointmentDates:[],maxAvailableSlots:0,autocomplete:this.getAutocomplete(t.name)};return o.fieldIsAppointmentCalenderField(r)?o.mapToAppointmentCalendarField(r):r})}static stringifyFieldValue(e,t){if(e.label)return e.label;let r=e.value;return t==="list"||t==="multilist"?r.replaceAll("#",", "):t==="appointmentCalendar"||t==="appointmentCalendarLinkToCollectionCalendar"?o.stringifyAppointmentDate(r):t==="document"?o.getFileName(r):r}static isAppointmentValue(e){return"calendarId"in e&&"timeFrom"in e&&"timeTo"in e}static stringifyAppointmentDate(e){let t=JSON.parse(e),r=o.isAppointmentValue(t)?t:void 0;if(!r)return"";let n=new Date(r.date),i=o.stringifyDateMember(n.getDate()),a=o.stringifyDateMember(n.getMonth()+1);return`Le ${i}/${a}/${n.getUTCFullYear()} de ${r.timeFrom} \xE0 ${r.timeTo}`}static getAutocomplete(e){return e==="name"||e==="email"?e:e==="phone"?"tel":e==="text"?"on":"off"}static getFileName(e){let t=e.split("/");return t[t.length-1]}static mapToAppointmentCalendarField(e){let t=o.getAvailableDates(e),r=Math.max(...t.map(n=>n.slots.length));return p(l({},e),{maxAvailableSlots:r,availableAppointmentDates:t})}static getAvailableDates(e){let t=e.extraData.find(i=>i.name==="AppointmentAvailableDates"&&i.value.includes('"availableDates"')),r=t?JSON.parse(t.value):void 0,n=r&&"availableDates"in r?r.availableDates:void 0;if(!n)throw new Error(`No available dates for field ${e.name}`);return n.map(i=>p(l({},i),{slots:i.slots.map(a=>p(l({},a),{id:`${i.date}-${a.timeFrom}`}))}))}static fieldIsAppointmentCalenderField(e){return e.type==="appointmentCalendar"||e.type==="appointmentCalendarLinkToCollectionCalendar"}static stringifyDateMember(e){return e>=10?e.toString():`0${e}`}};var y=class o{apiDynamicFormsService=d(b);contratService=d(h);allForms;currentFormSteps=[];currentStepIndex=0;currentGeoCoordinates={lat:0,lng:0};areDynamicFormsLoading=!1;constructor(){this.contratService.onContractChanged$.pipe(S()).subscribe(()=>{this.allForms=void 0})}async getFormSummaries(){return await this.loadDynamicForms(),this.allForms?.map(e=>({id:e.formId,title:e.formName,icon:e.formImgWeb,description:e.formDescription,formRoute:`dynamic/${e.formCode}`,externalLink:e.formUrl}))??[]}async getDynamicForm(e){await this.loadDynamicForms();let t=this.allForms?.find(i=>i.formCode===e);if(t)return this.resetCurrentForm(),this.currentFormSteps.push(t),t;let r=await this.apiDynamicFormsService.dynamicFormControllerGetFormByCodeV1({formcode:e}),n=this.dynamicFormToForm(r,!0);return this.resetCurrentForm(),this.currentFormSteps.push(n),n}async submitStep(e,t){if(!this.currentFormSteps[this.currentStepIndex])throw new Error(`No form steps for index ${this.currentStepIndex}`);let r=`${e[0].step}__${e[0].substepIteration}`;this.currentFormSteps[this.currentStepIndex].formValues[r]=e;let n=this.formToDynamicForm(this.currentFormSteps[this.currentStepIndex]);t&&(this.currentGeoCoordinates=t),n.gpsCoordinates=this.currentGeoCoordinates;let i=await this.apiDynamicFormsService.dynamicFormControllerProcessFormV1({body:n}),a=this.dynamicFormToForm(i,!1);this.currentStepIndex++;let s=this.currentFormSteps[this.currentStepIndex];if(s?.currentStep===a.currentStep){let c=`${a.currentStep}__${a.currentSubstep}`;return a.formValues[c]=s.formValues[c],this.currentFormSteps[this.currentStepIndex]=a,a}return s&&(this.currentFormSteps=this.currentFormSteps.filter((c,f)=>f<this.currentStepIndex),a.formValues=this.resetOutdatedFormValues(a)
1),this.currentFormSteps.push(a),a}formValuesSummary(){let e=this.currentFormSteps[this.currentFormSteps.length-1];if(e.isCompleted&&e.isSubmissionAllowed)return Object.keys(e.formValues).map(t=>{let r=this.currentFormSteps.find(i=>`${i.currentStep}__${i.currentSubstepIteration}`===t);if(!r)return;let n=e.formValues[t].map(i=>{let a=r.currentFields.find(s=>s.name===i.name);if(a)return{label:a.label.replace("*",""),value:m.stringifyFieldValue(i,i.type),isPicture:i.type==="picture"}}).filter(i=>i!==void 0);return{stepTitle:r.currentStepTitle,values:n}}).filter(t=>t!==void 0)}repeatableStepValuesSummary(){let e=this.currentFormSteps[this.currentFormSteps.length-1],r=Object.keys(e.formValues).filter(n=>n.includes(e.currentStep)).map(n=>e.formValues[n]);if(r?.length)return r?.map(n=>n.map(i=>({label:e.currentFields.find(s=>s.name===i.name)?.label.replace("*","")??"",value:m.stringifyFieldValue(i,i.type),isPicture:i.type==="picture"})))}async submitForm(){if(!this.currentFormSteps[this.currentStepIndex])throw new Error(`No form steps for index ${this.currentStepIndex}`);let e=this.formToDynamicForm(this.currentFormSteps[this.currentStepIndex]);return e.gpsCoordinates=this.currentGeoCoordinates,this.apiDynamicFormsService.dynamicFormControllerFinalyzeFormV1({body:e})}resetOutdatedFormValues(e){return this.currentFormSteps.map(r=>`${r.currentStep}__${r.currentSubstepIteration}`).reduce((r,n)=>(r[n]=e.formValues[n],r),{})}getPreviousStep(){return this.currentStepIndex--,this.currentFormSteps[this.currentStepIndex]}getFirstStep(){return this.currentStepIndex=0,this.currentFormSteps[this.currentStepIndex]}resetCurrentForm(){this.currentFormSteps=[],this.currentStepIndex=0,this.currentGeoCoordinates={lat:0,lng:0}}async loadDynamicForms(){try{if(!this.allForms&&!this.areDynamicFormsLoading){this.areDynamicFormsLoading=!0;let e=await this.apiDynamicFormsService.dynamicFormControllerGetFormsV1();this.allForms=e.map(t=>this.dynamicFormToForm(t,!0)),this.areDynamicFormsLoading=!1}}catch{console.log("An error happened while loading forms"),this.areDynamicFormsLoading=!1}}dynamicFormToForm(e,t){let r=e.currentStepSubTitle.match(/^(?<start>[\s\S]*)\[(?<label>.*)\]\((?<link>https?:\/\/.*)\)(?<end>[\s\S]*)$/m),n=r?.groups?{label:r.groups.label,url:r.groups.link}:void 0,i=this.getStepSubTitles(r,e);return p(l({},e),{isFirstStep:t,formValues:e.formValues.reduce((a,s)=>{let u=`${s.step}__${s.substepIteration}`;return a[u]?a[u].push(s):a[u]=[s],a},{}),currentFields:m.mapToFormFields(e.currentFields),currentStepSubTitles:i,stepSubTitleLink:n})}getStepSubTitles(e,t){return(e?.groups?e.groups.start+e.groups.end:t.currentStepSubTitle).split(` 2 3`).map(n=>n.split(` 4`))}formToDynamicForm(e){return{contractId:e.contractId,currentFields:m.mapToDynamicFormFields(e.currentFields),currentStep:e.currentStep,currentStepData:e.currentStepData,currentStepSubTitle:this.toCurrentStepTitle(e),currentStepTitle:e.currentStepTitle,currentSubstep:e.currentSubstep,currentSubstepIteration:e.currentSubstepIteration,formCode:e.formCode,formDescription:e.formDescription,formId:e.formId,formImg:e.formImg,formImgWeb:e.formImgWeb,formIsActive:e.formIsActive,formName:e.formName,formUrl:e.formUrl,gpsCoordinates:e.gpsCoordinates,isCompleted:e.isCompleted,isRepeatingEndlessly:e.isRepeatingEndlessly,isSubmissionAllowed:e.isSubmissionAllowed,userId:e.userId,formValues:Object.values(e.formValues).flat()}}toCurrentStepTitle(e){return e.currentStepSubTitles.map(t=>t.join(` 5`)).join(` 6 7`)}static \u0275fac=function(t){return new(t||o)};static \u0275prov=F({token:o,factory:o.\u0275fac,providedIn:"root"})};export{m as a,y as b};
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.