<template>
  <component
    :is="type"
    v-model="value"
    :question="question"
    @expr="expr"
    :evaluation-items="evaluationItems"
    :item-index="itemIndex"
    :index="index"
  />
</template>
<script lang="ts">
import Vue from "vue";
import QuestionFormMixin from "../../../../../mixins/question-form-mixin";
import Assign from "./assign.vue";
import Auto from "./auto.vue";
import Score from "./score.vue";
import { ExprConditionType } from "@wg-npm/survey-core/src/models";

export default Vue.extend({
  name: "condition",
  mixins: [QuestionFormMixin],
  components: {
    ASSIGN: Assign,
    AUTO: Auto,
    SCORE: Score,
  },
  props: {
    type: {
      type: String,
      required: true,
    },
    value: {
      type: Object,
      required: true,
    },
    index: {
      type: Number,
      required: true,
    },
    evaluationItems: {
      type: Array,
      required: true,
    },
    itemIndex: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      exprConditionType: ExprConditionType.AUTO,
      exprConditionTypes: [
        ExprConditionType.AUTO,
        ExprConditionType.ASSIGN,
        ExprConditionType.SCORE,
      ],
    };
  },
  methods: {
    expr(value) {
      this.$emit("expr", this.index, value);
    },
  },
});
</script>
