<template>
  <div class="question">
    <Row v-show="showQuestionScoreSlider">
      <div class="slider-container">
        <Slider
          class="slider"
          :min="question.options.minRange"
          :max="question.options.maxRange"
          :step="sliderStep"
          show-input
          show-tips="always"
        ></Slider>
        <div class="text-desc" v-show="extremeValueLabelSelected">
          <span>
            {{
              t(
                `survey_creator.question.scoring.extreme_value_labels.${question.options.extremeValueLabel}.minValue`
              )
            }}
          </span>
          <span>
            {{
              t(
                `survey_creator.question.scoring.extreme_value_labels.${question.options.extremeValueLabel}.maxValue`
              )
            }}
          </span>
        </div>
      </div>
    </Row>
    <div v-for="(subQuestion, index) in question.subQuestions" :key="index">
      <Divider
        class="question-type-desc"
        v-if="!isPreview"
        orientation="left"
        size="small"
        >{{
          t(
            "survey_creator.question.sub_questions",
            $rootComponent.currentLanguage
          )
        }}
      </Divider>
      <div class="sub-question-title">
        <span class="number"
          >{{ question.header.number }}.{{ subQuestion.number }}</span
        >
        <span class="content">{{ subQuestion.text | translate(true) }}</span>
        <!-- slider & input & label -->
        <Row>
          <div class="slider-container">
            <Slider
              class="slider"
              :min="question.options.minRange"
              :max="question.options.maxRange"
              :step="sliderStep"
              show-input
              show-tips="always"
            ></Slider>
            <div class="text-desc" v-show="extremeValueLabelSelected">
              <span>
                {{
                  t(
                    `survey_creator.question.scoring.extreme_value_labels.${question.options.extremeValueLabel}.minValue`
                  )
                }}
              </span>
              <span>
                {{
                  t(
                    `survey_creator.question.scoring.extreme_value_labels.${question.options.extremeValueLabel}.maxValue`
                  )
                }}
              </span>
            </div>
          </div>
        </Row>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import Vue from "vue";
import { Row, Divider, Slider } from "view-design";
import LocaleMixin from "../../../mixins/locale-mixin";
import { QuestionMatrixModel } from "@wg-npm/survey-core";
export default Vue.extend({
  name: "matrix",
  components: { Row, Divider, Slider },
  mixins: [LocaleMixin],
  inject: ["$rootComponent"],
  props: {
    question: {
      type: Object as () => QuestionMatrixModel,
      required: true,
    },
    maxScore: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {};
  },
  created() {},
  computed: {
    showQuestionScoreSlider() {
      return !(
        this.question.subQuestions && this.question.subQuestions.length > 0
      );
    },
    sliderStep: function () {
      return this.question.options.decimalPlaces == 0 ? 1 : 0.1;
    },
    extremeValueLabelSelected: function () {
      return this.question.options.extremeValueLabelEnabled;
    },
  },
});
</script>

<style lang="less" scoped>
.slider-container {
  margin-bottom: 18px;
  width: 100%;
}

.slider {
  width: 85%;
  margin-left: 66px;
  margin-right: 134px;
  margin-top: 16px;
}

.text-desc {
  display: flex;
  justify-content: space-between;
  width: 85%;
  padding-left: 50px;
}
</style>
