/*!
 * KoliBri - The accessible HTML-Standard
 */
import { watchValidator } from "../utils";
import { a11yHint, uiUxHint } from "../utils/a11y.tipps";
const READABLE_CHARS = /[a-zA-Z0-9äöüÄÖÜß]/g;
const ONLY_NUMBERS = /^\d+$/;
function countReadableChars(str) {
    var _a;
    return typeof str === 'string' ? ((_a = str.match(READABLE_CHARS)) === null || _a === void 0 ? void 0 : _a.length) || 0 : 0;
}
export function hasEnoughReadableChars(str, min = 1) {
    return countReadableChars(str) >= min;
}
export function containsOnlyNumbers(str) {
    return ONLY_NUMBERS.test(str);
}
function getValidationOptions(options) {
    var _a;
    return Object.assign(Object.assign({}, options), { hooks: {
            afterPatch: (value, state, component, key) => {
                var _a, _b;
                if (typeof ((_a = options.hooks) === null || _a === void 0 ? void 0 : _a.afterPatch) === 'function') {
                    (_b = options.hooks) === null || _b === void 0 ? void 0 : _b.afterPatch(value, state, component, key);
                }
                if (typeof value === 'string' && hasEnoughReadableChars(value, 3) === false && containsOnlyNumbers(value) === false) {
                    a11yHint(`The heading or label ("${value}") is inaccessible. A label should consist of at least three readable characters.`);
                }
                if (typeof value === 'string' && value.length > 80) {
                    uiUxHint(`A heading or label should not be longer than 80 characters.`);
                }
            },
            beforePatch: (_a = options.hooks) === null || _a === void 0 ? void 0 : _a.beforePatch,
        } });
}
const LABEL_VALUES = new Set(['string']);
export const validateLabel = (component, value, options = {}) => {
    watchValidator(component, '_label', (value) => typeof value === 'string', LABEL_VALUES, value, getValidationOptions(options));
};
export const validateLabelWithExpertSlot = validateLabel;
//# sourceMappingURL=label.js.map
