<template>
  <buttonQuestion
    class="radioQuestion"
    isOverflowScrollable
    selectingInitiatesLoad
    :questionText="questionText"
    :answers="models"
    groupName="ChooseVehicleModel"
    textPosition="text-start"
    v-model="selectedValue"
    isRequired=true
  />
</template>

<script>
import buttonQuestion from "@/common-components/button-question/button-question";
// Supporting files
import store from "@/store";
import { storeActions } from "@/constants/store-actions.js";
import baseMixin from "@/mixins/base-mixin.js";

export default {
  name: "model-question",
  data() {
    return {
      models: Array,
    };
  },
  props: {
    modelValue: String,
    cmsWidgetName: String,
  },
  computed: {
    questionText(){
      return this.getCmsContent(this.cmsWidgetName, 'QuestionText');
    },
    selectedValue: {
      get: function() {
        const modelValueAsArray = this.modelValue ? [this.modelValue] : [];
        return modelValueAsArray;
      },
      set: function(newValue) {
        this.$emit("update:modelValue", newValue);
      }
    }
  },
  components: {
    buttonQuestion,
  },
  methods: {
    loadInitialData() {
      return baseMixin.methods.dispatchStoreAction(
        storeActions.GET_VEHICLE_MODELS,
        { year: store.getters.vehicle.year, make: store.getters.vehicle.make }
      );
    },
    initializeComponent(initialData) {
      this.models = initialData;
    },
  },
};
</script>
