<template>
    <alert
        v-for="alert in prefixedAlertReasons"
        :key="alert.cmsWidgetName"
        :ref="alert.cmsWidgetName"
        class="mt-5 mb-4"
        :cmsWidgetName="alert.cmsWidgetName"
        alertClass="alert-warning" />
</template>
<script>
import alert from "@/ux-components/alert/alert";
import { getAlertReasons } from "@/layouts/schedule/helpers/schedule-helper";

export default {
    name: "locationAlerts",
    data() {
        return {
            alertReasons: [],
        };
    },
    props: {
        cmsWidgetPrefix: {
            type: String,
            default: "",
        },
    },
    computed: {
        prefixedAlertReasons() {
            return this.alertReasons.reduce((newObj, alert) => {
                newObj.push({
                    cmsWidgetName: `${this.cmsWidgetPrefix}${alert}`,
                    alertReason: alert,
                });
                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") !== "";
        },
    },
    components: {
        alert,
    },
};
</script>
