"use strict";

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

var _insertBefore = require("./insertBefore");

var _replaceUtils = require("./replaceUtils");

function hackForComposes(rule, hoveredSelectors, params) {
  const {
    Rule
  } = params;

  if (hoveredSelectors.length === 0) {
    return;
  } // NOTE: we create Empty Rule with hovered selectors that :hover removed from hover selector
  // Reason: when composes looking for selector it most be at least empty rule other wise composes will throw error.


  (0, _insertBefore.insertBefore)(rule, new Rule({
    selector: hoveredSelectors.map(_replaceUtils.removeHoverFromSelector).join(',')
  }));
}
/**
 * NOTE: this function will remove rule if the rule has no normal selectors.
 * @param {Rule} rule
 * @returns
 */


function removeRuleIfNoNormalSelectors(normalSelectors, rule) {
  if (normalSelectors.length) {
    // NOTE: removed hovered selectors
    // eslint-disable-next-line no-param-reassign
    rule.selector = normalSelectors.join(',');
  } else {
    rule.remove();
  }
}