"use strict";

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

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

function insertBefore(node, newNode) {
  newNode && node.parent.insertBefore(node, newNode);
  return newNode;
} // function insertAfter(node, newNode) {
//   newNode && node.parent.insertAfter(node, newNode);
//   return newNode;
// }


function insertNearBy(node, newNode) {
  if (!newNode) {
    return newNode;
  } // we use insertBefore Because we wouldn't end up recursive (repeated) check and creation


  if ((0, _typeCheckUtils.isParentAtRule)(node) && (0, _typeCheckUtils.isAtRule)(newNode)) {
    return insertNearBy(node.parent, newNode);
  }

  return insertBefore(node, newNode); // return insertAfter(node, newNode);
  // return newNode;
}