{"version":3,"file":"sharedActions-24y4nw7M.js","sources":["../../../app/javascript/components/builder/components/mixins/sharedActions.js"],"sourcesContent":["import set from \"lodash/set\";\nimport isEmpty from \"lodash/isEmpty\";\nimport escape from \"lodash/escape\";\nimport { getValueOrLabelByFieldId } from \"@/helpers/utils\";\n\nconst sharedActions = {\n props: {\n styling: {\n type: Object,\n required: true,\n },\n questionNumber: {\n type: Number,\n default: 0,\n },\n formElements: {\n type: Array,\n required: true,\n },\n variables: {\n type: Array,\n required: true,\n },\n item: {\n type: Object,\n required: true,\n },\n editing: {\n type: Boolean,\n default: false,\n },\n hasMultipleFields: {\n type: Boolean,\n default: false,\n },\n showLabel: {\n type: Boolean,\n default: true,\n },\n allowedRoleIds: {\n type: Array,\n default: () => [],\n },\n allowAllFields: {\n type: Boolean,\n default: false,\n },\n },\n emits: [\"next\", \"form-value-changed\"],\n data() {\n return {\n timeout: null,\n };\n },\n computed: {\n label() {\n const { isHidden, label } = this.item;\n\n if (!this.showLabel) return \"\";\n\n let question = this.replaceTagWithAnswer(label);\n\n const showQuestionNumber =\n this.questionNumber && this.styling.showQuestionNumber && !isHidden;\n\n return showQuestionNumber\n ? `Q${this.questionNumber}. ${question}`\n : question;\n },\n description() {\n if (!this.showLabel) return;\n\n return this.replaceTagWithAnswer(this.item.description);\n },\n correctOptions() {\n return this.item.options.filter(\n (option) =>\n this.item.quizScore.hasOwnProperty(option.id) &&\n this.item.quizScore[option.id].value > 0,\n );\n },\n correctAnswers() {\n return this.correctOptions.map((option) => option.id);\n },\n correctAnswerLabels() {\n return this.correctOptions.map((option) => option.label);\n },\n revealAnswer: {\n get() {\n return (\n this.item.isQuizField &&\n !this.editing &&\n this.hasPositiveScores &&\n this.styling.showFeedback &&\n this.item.revealAnswer\n );\n },\n set(value) {\n set(this.item, \"revealAnswer\", value);\n },\n },\n isEditingDisabled() {\n return this.revealAnswer && !this.item.allowEditing;\n },\n revealAnswerStyle() {\n return {\n color: this.styling.fontColor || \"#575757\",\n \"user-select\": \"none\",\n \"margin-top\": \"8px\",\n };\n },\n showAnswerText() {\n return (\n !this.editing &&\n this.item.isQuizField &&\n this.hasPositiveScores &&\n this.styling.showFeedback &&\n !isEmpty(this.item.value) &&\n !this.revealAnswer\n );\n },\n hasPositiveScores() {\n // Check if any options has score more than 0 (correct answer)\n return Object.values(this.item.quizScore).some(\n (values) => values.value > 0,\n );\n },\n isDisabled() {\n // Check for property called hasFieldAssignee in item\n if (this.item.hasOwnProperty(\"hasFieldAssignee\")) {\n if (!this.item.hasFieldAssignee) return false;\n\n if (this.allowAllFields) return false;\n\n const fieldRoleId = parseInt(this.item.fieldRoleId);\n if (!fieldRoleId) return true;\n\n return !this.allowedRoleIds.includes(fieldRoleId);\n }\n return false;\n },\n },\n watch: {\n \"item.value\": {\n handler() {\n if (this.item.componentFromRepeatField) return;\n\n this.$emit(\"form-value-changed\", this.item);\n },\n deep: true,\n },\n \"item.customOptionValue\": {\n handler() {\n this.$emit(\"form-value-changed\", this.item);\n },\n },\n \"item.children\": {\n handler() {\n this.$emit(\"form-value-changed\", this.item);\n },\n deep: true,\n },\n \"item.rows\": {\n handler() {\n if (this.item.type === \"repeat-field\") {\n this.$emit(\"form-value-changed\", this.item);\n }\n },\n deep: true,\n },\n },\n methods: {\n autoProgressToNext() {\n if (\n this.styling.multiPage &&\n !this.hasMultipleFields &&\n this.styling.autoProgression &&\n !this.styling.showFeedback\n ) {\n if (this.timeout) {\n // clear previous timeout if not executed yet\n clearTimeout(this.timeout);\n this.timeout = null;\n }\n this.timeout = setTimeout(() => {\n this.$emit(\"next\");\n this.timeout = null;\n }, 750);\n }\n },\n replaceTagWithAnswer(question) {\n const regex = /@\\{(.*?)\\}/;\n let matches = question?.match(regex);\n\n while (matches?.length > 0) {\n if (matches[1].startsWith(\"variable_\")) {\n matches[1] = matches[1].split(\"_\")[1];\n }\n\n question = question.replace(\n matches[0],\n this.editing\n ? this.createInformationRecallBadge(matches[1])\n : this.retrieveFieldData(matches[1]),\n );\n matches = question.match(regex);\n }\n\n return question;\n },\n createInformationRecallBadge(id) {\n const value = getValueOrLabelByFieldId({\n id,\n items: this.formElements,\n variables: this.variables,\n });\n return this.createStyledBadge(value);\n },\n createStyledBadge(value) {\n return `\n ${value}\n `;\n },\n retrieveFieldData(id) {\n const value = getValueOrLabelByFieldId({\n id,\n items: this.formElements,\n variables: this.variables,\n outputType: \"only-value\",\n });\n return escape(value);\n },\n processInputValue(value) {\n const regex = /@{([^}]+)}/g;\n const regExToGetNumber = /\\d+(\\.\\d+)?/;\n let processedValue = value.toString();\n let matches = processedValue.match(regex);\n\n while (matches?.length > 0) {\n const match = matches[0]; // Get the full match including '@{}'\n let matchWithoutSymbol = match.slice(2, -1); // Remove the '@{' and '}' symbols\n\n if (matchWithoutSymbol.startsWith(\"variable_\")) {\n //get variable uuid if matchWithoutSymbol is variable\n matchWithoutSymbol = matchWithoutSymbol.split(\"_\")[1];\n }\n\n let processedMatch = this.retrieveFieldData(matchWithoutSymbol); // Get the processed value for the match\n let processedMatchToNumber = 0;\n\n // conver the value to Array and add each value to get final value\n processedMatch.split(\",\").forEach((value) => {\n // get the number from the value ex: 10% => 10, Product 1 - $5.5 => 5.5, 1 => 1\n const matched = value.match(regExToGetNumber);\n const number = matched ? Number(matched[0]) : 0;\n processedMatchToNumber += number;\n });\n\n processedValue = processedValue.replace(match, processedMatchToNumber);\n matches = processedValue.match(regex);\n }\n return processedValue;\n },\n },\n};\n\nexport default sharedActions;\n"],"names":["sharedActions","isHidden","label","question","option","value","set","isEmpty","values","fieldRoleId","regex","matches","id","getValueOrLabelByFieldId","escape","regExToGetNumber","processedValue","match","matchWithoutSymbol","processedMatch","processedMatchToNumber","matched","number"],"mappings":"4cAKK,MAACA,EAAgB,CACpB,MAAO,CACL,QAAS,CACP,KAAM,OACN,SAAU,EACX,EACD,eAAgB,CACd,KAAM,OACN,QAAS,CACV,EACD,aAAc,CACZ,KAAM,MACN,SAAU,EACX,EACD,UAAW,CACT,KAAM,MACN,SAAU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