import Vue from "vue"; import _ from "lodash"; export default Vue.extend({ inject: ["$rootComponent"], props: { value: { type: Object, required: true, }, evaluationItems: { type: Array, required: true, }, itemIndex: { type: Number, required: true, }, index: { type: Number, required: true, }, }, data() { return { primaryLanguage: "", choices: [], operators: ["=", ">=", ">", "<=", "<", "!="], }; }, watch: { value: { handler(newValue, oldValue) { this.$emit("expr", this.generateExpr()); this.choices = this.buildChoices(this.value.scope); }, deep: true, immediate: true, }, }, mounted() { this.primaryLanguage = this.$rootComponent.primaryLanguage; this.choices = this.buildChoices(this.value.scope); }, methods: { buildChoices(scope) { const choices = new Array(); const questions = this.$rootComponent.currentSurvey.questions; _.forEach(questions, (question) => { if ( _.includes(scope, question.id) || !_.isEmpty( _.intersection( scope, // @ts-ignore _.map(_.get(question, "subQuestions", []), "id") ) ) ) { _.forEach(question.choices, (choice) => { if (!_.isNil(choice.text[this.primaryLanguage])) { choices.push(choice.text[this.primaryLanguage]); } }); } }); return _.uniq(choices); }, generateExpr() { return ""; }, }, });