export class MaskBlock {
    constructor(option) {
        this._isSeparator = false;
        this._allowedKeys = [];
        this._locale = 'de-CH';
        this._from = option.from || 0;
        this._to = option.to || 0;
        this._isSeparator = option.isSeparator === undefined ? false : option.isSeparator;
        this._mask = option.mask || '_';
        this._allowedKeys = option.allowedKeys ? option.allowedKeys : this.allowedKeys;
        this._format = option.format;
    }
    format(value) {
        if (this._format) {
            return this._format(value.replace(this.mask, ''), this._locale, this.mask);
        }
        return value;
    }
    get isSeparator() {
        return this._isSeparator;
    }
    get to() {
        return this._to;
    }
    get from() {
        return this._from;
    }
    get mask() {
        if (typeof this._mask === 'function') {
            return this._mask(this._locale);
        }
        return this._mask;
    }
    get allowedKeys() {
        return this._allowedKeys;
    }
    onI18nChange(locale) {
        this._locale = locale;
    }
    getValueOfTheBlock(value) {
        return value.slice(this._from, this._to);
    }
    isTouched(value) {
        const blockValue = this.getValueOfTheBlock(value);
        return !blockValue.split('').every(char => char === this.mask);
    }
    verifyAllowedKeyHits(key) {
        if (this.isSeparator && key === this.mask) {
            return true;
        }
        else if (this.allowedKeys.indexOf(key) >= 0) {
            return true;
        }
        else {
            // context.stopPropagation()
            return false;
        }
    }
}
