<template>
    <alert
        v-for="alert in prefixedAlertReasons"
        :key="alert.cmsWidgetName"
        :ref="alert.cmsWidgetName"
        class="mt-2 mb-3"
        :cmsWidgetName="alert.cmsWidgetName"
        alertClass="alert-warning" />
</template>
<script>
import alert from '@/ux-components/alert/alert.vue';
import getAlertReasons from '@/layouts/schedule-page/helpers/schedule-helper';

export default {
    name: 'location-alerts',
    components: {
        alert
    },
    props: {
        cmsWidgetPrefix: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            alertReasons: []
        };
    },
    computed: {
        prefixedAlertReasons() {
            return this.alertReasons.reduce((newObj, alertReason) => {
                newObj.push({
                    cmsWidgetName: `${this.cmsWidgetPrefix}${alertReason}`,
                    alertReason
                });
                return newObj;
            }, []);
        }
    },
    methods: {
        loadInitialData(serviceLocationCtu, providerCtu) {
            let ctuToUse = serviceLocationCtu;
            if (providerCtu) {
                ctuToUse = providerCtu;
            }
            return getAlertReasons(ctuToUse);
        },
        initializeComponent(initialData) {
            this.alertReasons = initialData;
        },
        cmsHeadlineTextFound(widgetName) {
            return this.getCmsContent(widgetName, 'HeadlineText') !== '';
        }
    }
};
</script>
