var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var defaultOptions = {
    duration: 150,
    delay: 0,
    iterations: 1,
    easing: 'ease-in',
};
var animations = new WeakMap();
/**
 * Мерцание при вводе недоступных символов
 *
 * @param {Object} args
 * @param {HTMLElement|null} args.el Элемент, к которому применяется эффект.
 * @param {string} args.blinkColor Цвет мерцания в любом допустимом CSS-формате.
 * @param {KeyframeAnimationOptions} args.options Опции анимации (timing, duration и т.д.).
 *
 * @return {void}
 */
export function blink(_a) {
    var _b, _c, _d;
    var el = _a.el, blinkColor = _a.blinkColor, _e = _a.options, options = _e === void 0 ? {} : _e;
    if (!el) {
        return;
    }
    var config = __assign(__assign({}, defaultOptions), options);
    if ('animate' in el && typeof el.animate === 'function') {
        (_b = animations.get(el)) === null || _b === void 0 ? void 0 : _b.cancel();
        animations.set(el, el.animate([{ backgroundColor: blinkColor }, { backgroundColor: 'inherit' }], config));
        return;
    }
    // Fallback Safari <13.1
    el.dataset.originalTransition = (_c = el.dataset.originalTransition) !== null && _c !== void 0 ? _c : el.style.transition;
    el.dataset.originalBackgroundColor = (_d = el.dataset.originalBackgroundColor) !== null && _d !== void 0 ? _d : el.style.backgroundColor;
    clearTimeout(el.dataset.timeoutId);
    el.style.transition = el.dataset.originalTransition;
    el.style.backgroundColor = blinkColor;
    setTimeout(function () {
        var _a;
        if (!el) {
            return;
        }
        el.style.transition = "background-color ".concat(config.duration, "ms ").concat(config.delay, "ms ").concat(config.easing);
        el.style.backgroundColor = 'inherit';
        el.dataset.timeoutId = setTimeout(function () {
            var _a, _b;
            if (!el) {
                return;
            }
            el.style.transition = (_a = el.dataset.originalTransition) !== null && _a !== void 0 ? _a : '';
            el.style.backgroundColor = (_b = el.dataset.originalBackgroundColor) !== null && _b !== void 0 ? _b : '';
        }, parseInt(((_a = config.duration) === null || _a === void 0 ? void 0 : _a.toString()) || '0')).toString();
    }, 1);
}
//# sourceMappingURL=blink.js.map