// (C) 2024-2026 GoodData Corporation
import { getAlertMeasure } from "../utils/getters.js";
import { getSupportedInsightMeasuresByInsight } from "../utils/items.js";
export function useAlertValidation(alert, widget, insight, catalogDateDatasets, isNewAlert, canManageComparison = false) {
    const supportedMeasures = getSupportedInsightMeasuresByInsight(insight, catalogDateDatasets, canManageComparison, alert);
    const selectedMeasureExists = alert ? getAlertMeasure(supportedMeasures, alert.alert) : undefined;
    const isValid = isNewAlert || Boolean(!!widget && selectedMeasureExists);
    let invalidityReason = undefined;
    if (!widget) {
        invalidityReason = "missingWidget";
    }
    else if (!selectedMeasureExists) {
        invalidityReason = "missingMetric";
    }
    return { isValid, invalidityReason };
}
