"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.handleIgnores = handleIgnores;

var _typeCheckUtils = require("./typeCheckUtils");

const hoverIgnoreQuery = 'Hover:ignore';
const activeIgnoreQuery = 'Active:ignore';
const hoverActiveIgnoreQuery = 'HoverActive:ignore';

function handleIgnore() {
  let isIgnored = false;
  return {
    isIgnored: () => isIgnored,
    update: isGoingTobeIgnored => {
      isIgnored = isGoingTobeIgnored;
    },
    reset: () => {
      isIgnored = false;
    }
  };
} // eslint-disable-next-line no-unused-vars


function handleIgnores(options) {
  const hoverHandler = handleIgnore();
  const activeHandler = handleIgnore();

  function generateReturnValue() {
    return {
      hoverIgnored: hoverHandler.isIgnored(),
      activeIgnored: activeHandler.isIgnored()
    };
  }

  const ignoreCommentMap = {
    [hoverIgnoreQuery]: () => {
      hoverHandler.update(true);
    },
    [activeIgnoreQuery]: () => {
      activeHandler.update(true);
    },
    [hoverActiveIgnoreQuery]: () => {
      hoverHandler.update(true);
      activeHandler.update(true);
    }
  };
  return node => {
    if ((0, _typeCheckUtils.isComment)(node)) {
      const commentText = node.text.trim();
      ignoreCommentMap[commentText] && ignoreCommentMap[commentText](); //   NOTE: we return here because this is just comment we can skip it.

      return generateReturnValue();
    } //   NOTE: we get the here. But return after resetting for next. Because these comment Only works for once.
    //  Even If we support multiple line Skip we must do it in reset or separate method.


    const returnValue = generateReturnValue();
    hoverHandler.reset();
    activeHandler.reset();
    return returnValue;
  };
}