<template>
    <!-- Modal -->
    <div
        :id="cmsWidgetName"
        class="modal fade modal-component"
        tabindex="-1"
        aria-labelledby="ModalComponentLabel"
        aria-hidden="true"
        v-on="{ 'hidden.bs.modal': resetButtonStyle }">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <button
                        type="button"
                        class="btn-close"
                        data-bs-dismiss="modal"
                        aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <label
                        :aria-label="ModalQuestionText"
                        class="form-label text-center w-100 mb-5 fw-bold"
                        v-html="ModalQuestionText"></label>
                </div>
                <buttonQuestion
                v-model="selectedValue"
                class="radioQuestion"
                :questionText="questionText"
                :answers="ModalSelectOptionAnswers"
                groupName="ChooseVehicleYear"
                :validationRules="validationRules"
                isRequired />
                <div class="modal-footer px-5 py-4">
                    <buttonMain
                        ref="buttonMain"
                        class="w-100"
                        isPrimary
                        suppressLoader
                        :buttonText="ModalSelectButtonText"
                        data-bs-dismiss="modal"
                        @clickEvent="buttonClick" />
                </div>
            </div>
        </div>
    </div>
</template>

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

export default {
    name: 'button-question-modal',
    components: {
        buttonMain,
        buttonQuestion
    },
    props: {
        cmsWidgetName: String
    },
    computed: {
        ModalQuestionText() {
            return this.getCmsContent(this.cmsWidgetName, 'QuestionText');
        },
        ModalSelectButtonText() {
            return this.getCmsContent(this.cmsWidgetName, 'ButtonText');
        },
        ModalSelectOptionAnswers() {
            return this.getCmsContent(this.cmsWidgetName, 'Answers');
        }
    },
    methods: {
        resetButtonStyle() {
            this.$refs.buttonMain.resetButtonStyle();
        }
    }
};
</script>

<style lang="scss" scoped>
.modal {
    top: auto;
    bottom: 0;
    h5,
    strong,
    .subheader-text {
        color: $black;
    }
    .modal-header {
        border-bottom: none;
        .btn-close {
            background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M15.6874 1.82179L9.50889 8L15.6874 14.1782C16.1042 14.595 16.1042 15.2707 15.6874 15.6875C15.4843 15.8907 15.2146 16 14.9328 16C14.6514 16 14.3818 15.8906 14.1787 15.6875L8.00017 9.50934L1.82171 15.6875C1.6182 15.8907 1.34876 16 1.06708 16C0.785733 16 0.516056 15.8906 0.312965 15.6875C-0.10429 15.2706 -0.10429 14.5952 0.312797 14.1784L6.03276 8.45867L6.49146 8L0.312945 1.82177C-0.10429 1.40483 -0.10429 0.729418 0.312797 0.31262C0.728936 -0.104145 1.40489 -0.104051 1.82185 0.31262L7.54152 6.03202L8.00017 6.49065L14.1786 0.312472C14.5955 -0.104107 15.2707 -0.104201 15.6874 0.312452C16.1042 0.729289 16.1042 1.40496 15.6874 1.82179Z' fill='%231574A1'/%3E%3C/svg%3E%0A");
            opacity: 1;
        }
    }
    &.modal-component {
        .modal-dialog {
            max-width: 576px;
            margin: 0 auto;
            .modal-content {
                margin: 0 auto;
                box-shadow: 0px 16px 48px -16px rgba(0, 0, 0, 0.25);
                border-radius: 1.5rem 1.5rem 0 0;
                .modal-body {
                    padding-bottom: 0px;
                    padding-top:0px;
                    ul {
                        margin-bottom: 0;
                    }
                    p {
                        &:last-child {
                            margin-bottom: 0;
                        }
                    }
                }
            }
            &.modal-dialog-centered {
                align-items: flex-end;
                min-height: 100%;
            }
        }
        .modal-footer {
            border-top: none;
            background-color: $gray-100;
            box-shadow: 0px -1px 0px rgba(179, 180, 181, 0.3);
            button {
                margin: 0;
            }
        }
        .radioQuestion
        {
            padding-bottom: 20px;
            padding-right: 24px;
            padding-left: 24px;
        }
    }
}
body {
    .modal-backdrop {
        height: 100%;
        &.show {
            opacity: 0.4;
        }
    }
}
</style>
