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

<script>
import buttonQuestion from '@/digital-components/button-question/button-question.vue';

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