import { ColumnValidator } from '../../base/models/column-validator';
import { NumberTextFormat } from '../types';
const numberTextValidityFlagNames = [
    'invalidDecimalDigits',
    'invalidDecimalMaximumDigits',
    'decimalDigitsMutuallyExclusiveWithDecimalMaximumDigits',
    'moreThanOneUnitSpecified'
];
// The maximum and minimum allowed configuration for 'maximumFractionDigits'
// and 'minimumFractionDigits' on the NumberFormat.
const minimumValidDecimalDigits = 0;
const maximumValidDecimalDigits = 20;
/**
 * Validator for TableColumnNumberText.
 */
export class TableColumnNumberTextValidator extends ColumnValidator {
    constructor() {
        super(numberTextValidityFlagNames);
    }
    validateDecimalDigits(format, decimalDigits) {
        const shouldValidateDecimalDigitsValue = format === NumberTextFormat.decimal
            && typeof decimalDigits === 'number';
        const invalid = shouldValidateDecimalDigitsValue
            ? this.isInvalidDecimalDigitsValue(decimalDigits)
            : false;
        this.setConditionValue('invalidDecimalDigits', invalid);
    }
    validateDecimalMaximumDigits(format, decimalMaximumDigits) {
        const shouldValidateDecimalDigitsValue = format === NumberTextFormat.decimal
            && typeof decimalMaximumDigits === 'number';
        const invalid = shouldValidateDecimalDigitsValue
            ? this.isInvalidDecimalDigitsValue(decimalMaximumDigits)
            : false;
        this.setConditionValue('invalidDecimalMaximumDigits', invalid);
    }
    validateNoMutuallyExclusiveProperties(format, decimalDigits, decimalMaximumDigits) {
        const shouldValidateMutuallyExclusiveProperties = format === NumberTextFormat.decimal;
        const invalid = shouldValidateMutuallyExclusiveProperties
            ? typeof decimalDigits === 'number'
                && typeof decimalMaximumDigits === 'number'
            : false;
        this.setConditionValue('decimalDigitsMutuallyExclusiveWithDecimalMaximumDigits', invalid);
    }
    validateAtMostOneUnit(unitElements) {
        const invalid = unitElements.length > 1;
        this.setConditionValue('moreThanOneUnitSpecified', invalid);
    }
    isInvalidDecimalDigitsValue(decimalDigits) {
        return (decimalDigits < minimumValidDecimalDigits
            || decimalDigits > maximumValidDecimalDigits);
    }
}
//# sourceMappingURL=table-column-number-text-validator.js.map