/**
 * DevExtreme (esm/__internal/scheduler/options_validator/core/options_validator_error_handler.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
export class OptionsValidatorErrorHandler {
    constructor(validatorNameToErrorCodeMap, globalErrorHandler) {
        this.validatorNameToErrorCodeMap = validatorNameToErrorCodeMap;
        this.globalErrorHandler = globalErrorHandler
    }
    handleValidationResult(optionsValidatorResult) {
        if (true === optionsValidatorResult) {
            return
        }
        var uniqErrorCodes = Object.keys(optionsValidatorResult).reduce((set, validatorName) => {
            var errorCode = this.validatorNameToErrorCodeMap[validatorName];
            if (errorCode) {
                set.add(errorCode)
            }
            return set
        }, new Set);
        var errorCodeArray = [...uniqErrorCodes];
        errorCodeArray.forEach((errorCode, idx) => {
            var isLastErrorCode = idx === errorCodeArray.length - 1;
            if (!isLastErrorCode) {
                this.globalErrorHandler.logError(errorCode)
            } else {
                this.globalErrorHandler.throwError(errorCode)
            }
        })
    }
}
