'use strict';

var is = require('../is.cjs');

function hasClass(node, className) {
  if (node.classList)
    return node.classList.contains(className);
  const originClass = node.className;
  return ` ${originClass} `.includes(` ${className} `);
}
function addClass(node, className) {
  if (node.classList) {
    node.classList.add(className);
  } else {
    if (!hasClass(node, className))
      node.className = `${node.className} ${className}`;
  }
}
function removeClass(node, className) {
  if (node.classList) {
    node.classList.remove(className);
  } else {
    if (hasClass(node, className)) {
      const originClass = node.className;
      node.className = ` ${originClass} `.replace(` ${className} `, " ");
    }
  }
}
function classNames(...args) {
  const classes = [];
  for (let i = 0; i < args.length; i++) {
    const value = args[i];
    if (!value)
      continue;
    if (is.isString(value)) {
      classes.push(value);
    } else if (is.isArray(value)) {
      for (let j = 0; j < value.length; j++) {
        const inner = classNames(value[j]);
        if (inner)
          classes.push(inner);
      }
    } else if (is.isObject(value)) {
      for (const name in value) {
        if (value[name])
          classes.push(name);
      }
    }
  }
  return classes.join(" ");
}

exports.addClass = addClass;
exports.classNames = classNames;
exports.hasClass = hasClass;
exports.removeClass = removeClass;
//# sourceMappingURL=class.cjs.map
