<template>
    <transition name="fade" mode="out-in">
        <div class="windshield-chip-count-question" v-if="isAvailable" aria-live="polite">
            <buttonQuestion
                :questionText="questionText"
                :answers="answersFromCms"
                :groupName="groupName"
                buttonTypeString="listButtonHorizontal"
                useTextForValue
                v-model="selectedValue"
                :validationRules="validationRules"
                isRequired />
        </div>
    </transition>
</template>

<script>
import buttonQuestion from "@/digital-components/button-question/button-question";

export default {
    name: "windshieldOptions",
    props: {
        modelValue: [String, Number],
        groupName: String,
        isAvailable: Boolean,
        validationRules: String,
        cmsWidgetName: String,
    },
    computed: {
        questionText() {
            return this.getCmsContent(this.cmsWidgetName, "QuestionText");
        },
        answersFromCms() {
            return this.getCmsContent(this.cmsWidgetName, "Answers");
        },
        selectedValue: {
            get: function () {
                return this.modelValue;
            },
            set: function (newValue) {
                const numberValue = Number(newValue);
                this.$emit("update:modelValue", numberValue);
            },
        },
    },
    components: {
        buttonQuestion,
    },
};
</script>
