'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var CodeInput_tokens = require('../CodeInput.tokens.js');
var constants = require('../../../utils/constants.js');

var handleItemError = function handleItemError(_ref) {
  var _inputContainerRef$cu;
  var currentSymbol = _ref.currentSymbol,
    itemErrorBehavior = _ref.itemErrorBehavior,
    index = _ref.index,
    newCode = _ref.newCode,
    inputRefs = _ref.inputRefs,
    inputContainerRef = _ref.inputContainerRef,
    codeSetter = _ref.codeSetter;
  if (!inputRefs.current[index] || currentSymbol === ' ') {
    return;
  }
  var circleElement = (_inputContainerRef$cu = inputContainerRef.current) === null || _inputContainerRef$cu === void 0 ? void 0 : _inputContainerRef$cu.querySelector(".".concat(CodeInput_tokens.classes.itemCircle, "-").concat(index));
  switch (itemErrorBehavior) {
    case 'forbid-enter':
      newCode[index] = '';
      codeSetter(newCode);
      break;
    case 'remove-symbol':
    default:
      newCode[index] = '';
      codeSetter(newCode);
      if (circleElement) {
        circleElement.classList.add(CodeInput_tokens.classes.itemCircleError, CodeInput_tokens.classes.itemCircleErrorAnimation);
      }
      setTimeout(function () {
        if (circleElement) {
          circleElement.classList.remove(CodeInput_tokens.classes.itemCircleError, CodeInput_tokens.classes.itemCircleErrorAnimation);
        }
      }, constants.ANIMATION_TIMEOUT);
  }
};

exports.handleItemError = handleItemError;
