{"version":3,"file":"useFormStatus-vgJ2-XIN.js","sources":["../../../app/frontend/composables/useFormErrors.js","../../../app/frontend/composables/useFormStatus.js"],"sourcesContent":["import useHelpers from './helpers/useHelpers';\nimport useResponsiveWatcher from './useResponsiveWatcher';\nimport useSmoothScroller from './useSmoothScroller';\n\nconst useFormErrors = ({ firstWrongQuestion, swiperSlideAttributes, v$, touchUserForm, layout }) => {\n const { constructVuelidateAttribute } = useHelpers();\n const { isMobile } = useResponsiveWatcher();\n\n const showSlideErrors = (current) => {\n const isUserSlide = swiperSlideAttributes.value[current].some((attributes) => /^user\\./.test(attributes));\n if (isUserSlide && touchUserForm) touchUserForm();\n\n swiperSlideAttributes.value[current].forEach((attribute) => constructVuelidateAttribute(attribute, v$.value.form).$touch());\n };\n\n const returnToError = () => {\n if (isMobile.value && swiperSlideAttributes) {\n const firstWrongSection = Object.keys(swiperSlideAttributes.value).find((key) => {\n return swiperSlideAttributes.value[key].some((attribute) => constructVuelidateAttribute(attribute, v$.value.form).$invalid);\n }) || 1;\n layout.value.pageSwiper().slideTo(parseInt(firstWrongSection) - 1);\n showSlideErrors(firstWrongSection);\n } else {\n const elementToScroll = document.getElementById(firstWrongQuestion.value);\n const offset = 325;\n const { smoothScrollToElement } = useSmoothScroller();\n smoothScrollToElement(elementToScroll, offset);\n }\n };\n\n return {\n showSlideErrors,\n returnToError,\n };\n};\n\nexport default useFormErrors;\n","import { computed } from 'vue';\nimport useHelpers from './helpers/useHelpers';\nimport useResponsiveWatcher from './useResponsiveWatcher';\n\nconst useFormStatus = ({ state, swiperSlideAttributes, v$, layout }) => {\n /// HELPERS ///\n const { constructVuelidateAttribute } = useHelpers();\n const { isMobile } = useResponsiveWatcher();\n\n const allBelongingFields = computed(() => {\n // We use this regex to filter away Vuelidate fields as they begin with '$'\n const vuelidateField = new RegExp(/[$]+/);\n return Object.keys(v$.value.form).filter((el) => !vuelidateField.test(el)).filter((el) => !['user', 'userDetails'].includes(el));\n });\n\n const validBelongingFields = computed(() => {\n return allBelongingFields.value.filter((fieldName) => {\n return !v$.value.form[fieldName]?.$invalid;\n });\n });\n\n /// EXPORTS ///\n const swiperSlidesStatuses = computed(() => {\n return Object.fromEntries(Object\n .entries(swiperSlideAttributes.value)\n .map(([k, v]) => [k, statusOf(v)]),\n );\n });\n\n const percentageCompleted = computed(() => {\n const validInputs = () => {\n return state.form.user ? state.form.user.validUserFields.concat(validBelongingFields.value).length : validBelongingFields.value.length;\n };\n const totalInputs = () => {\n return state.form.user ? state.form.user.allUserFields.concat(allBelongingFields.value).length : allBelongingFields.value.length;\n };\n\n return parseInt((validInputs() / totalInputs() * 100).toFixed(0));\n });\n\n const formCompletionStatus = computed(() => {\n if (v$.value.$error) return 'error';\n\n return percentageCompleted.value === 100 ? 'success' : 'ongoing';\n });\n\n const subSectionUserProfilingStatus = computed(() => {\n // The status of the Sub-Section UserProfiling is computed differently on desktop\n // (where it's one group of questions) than on mobile (where it's split in two slides,\n // each of them having its own status)\n const currentSlide = layout.value?.current;\n return isMobile.value ? swiperSlidesStatuses.value[currentSlide] : statusOf(['user']);\n });\n\n const statusOf = (attributes) => {\n if (attributes.filter((fieldName) => constructVuelidateAttribute(fieldName, v$.value.form).$errors.length).length) return 'error';\n return attributes.filter((fieldName) => constructVuelidateAttribute(fieldName, v$.value.form).$invalid).length ? 'ongoing' : 'success';\n };\n\n const updateUserStatus = ({ invalid, allUserFields, validUserFields }) => {\n state.form.user.valid = !invalid;\n state.form.user.allUserFields = allUserFields;\n state.form.user.validUserFields = validUserFields;\n };\n\n return {\n swiperSlidesStatuses,\n statusOf,\n percentageCompleted,\n formCompletionStatus,\n updateUserStatus,\n subSectionUserProfilingStatus,\n };\n};\n\nexport default useFormStatus;\n"],"names":["useFormErrors","firstWrongQuestion","swiperSlideAttributes","v$","touchUserForm","layout","constructVuelidateAttribute","useHelpers","isMobile","useResponsiveWatcher","showSlideErrors","current","attributes","attribute","firstWrongSection","key","elementToScroll","offset","smoothScrollToElement","useSmoothScroller","useFormStatus","state","allBelongingFields","computed","vuelidateField","el","validBelongingFields","fieldName","_a","swiperSlidesStatuses","k","v","statusOf","percentageCompleted","validInputs","totalInputs","formCompletionStatus","subSectionUserProfilingStatus","currentSlide","invalid","allUserFields","validUserFields"],"mappings":"yMAIK,MAACA,EAAgB,CAAC,CAAE,mBAAAC,EAAoB,sBAAAC,EAAuB,GAAAC,EAAI,cAAAC,EAAe,OAAAC,KAAa,CAClG,KAAM,CAAE,4BAAAC,GAAgCC,IAClC,CAAE,SAAAC,GAAaC,IAEfC,EAAmBC,GAAY,CACfT,EAAsB,MAAMS,CAAO,EAAE,KAAMC,GAAe,UAAU,KAAKA,CAAU,CAAC,GACrFR,GAAeA,IAElCF,EAAsB,MAAMS,CAAO,EAAE,QAASE,GAAcP,EAA4BO,EAAWV,EAAG,MAAM,IAAI,EAAE,OAAQ,CAAA,CAC9H,EAiBE,MAAO,CACL,gBAAAO,EACA,cAjBoB,IAAM,CAC1B,GAAIF,EAAS,OAASN,EAAuB,CAC3C,MAAMY,EAAoB,OAAO,KAAKZ,EAAsB,KAAK,EAAE,KAAMa,GAChEb,EAAsB,MAAMa,CAAG,EAAE,KAAMF,GAAcP,EAA4BO,EAAWV,EAAG,MAAM,IAAI,EAAE,QAAQ,CAC3H,GAAK,EACNE,EAAO,MAAM,aAAa,QAAQ,SAASS,CAAiB,EAAI,CAAC,EACjEJ,EAAgBI,CAAiB,CACvC,KAAW,CACL,MAAME,EAAkB,SAAS,eAAef,EAAmB,KAAK,EAClEgB,EAAS,IACT,CAAE,sBAAAC,GAA0BC,IAClCD,EAAsBF,EAAiBC,CAAM,CAC9C,CACL,CAKA,CACA,EC9BMG,EAAgB,CAAC,CAAE,MAAAC,EAAO,sBAAAnB,EAAuB,GAAAC,EAAI,OAAAE,CAAM,IAAO,CAEtE,KAAM,CAAE,4BAAAC,GAAgCC,IAClC,CAAE,SAAAC,GAAaC,IAEfa,EAAqBC,EAAS,IAAM,CAExC,MAAMC,EAAiB,IAAI,OAA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