import { __exports as toBeDisabled$1 } from "../../../../_virtual/to-be-disabled.js";
import "./utils.js";
import { __exports as utils } from "../../../../_virtual/utils.js";
Object.defineProperty(toBeDisabled$1, "__esModule", {
  value: true
});
toBeDisabled$1.toBeDisabled = toBeDisabled;
toBeDisabled$1.toBeEnabled = toBeEnabled;
var _utils = utils;
const FORM_TAGS = ["fieldset", "input", "select", "optgroup", "option", "button", "textarea"];
function isFirstLegendChildOfFieldset(element, parent) {
  return (0, _utils.getTag)(element) === "legend" && (0, _utils.getTag)(parent) === "fieldset" && element.isSameNode(Array.from(parent.children).find((child) => (0, _utils.getTag)(child) === "legend"));
}
function isElementDisabledByParent(element, parent) {
  return isElementDisabled(parent) && !isFirstLegendChildOfFieldset(element, parent);
}
function isCustomElement(tag) {
  return tag.includes("-");
}
function canElementBeDisabled(element) {
  const tag = (0, _utils.getTag)(element);
  return FORM_TAGS.includes(tag) || isCustomElement(tag);
}
function isElementDisabled(element) {
  return canElementBeDisabled(element) && element.hasAttribute("disabled");
}
function isAncestorDisabled(element) {
  const parent = element.parentElement;
  return Boolean(parent) && (isElementDisabledByParent(element, parent) || isAncestorDisabled(parent));
}
function isElementOrAncestorDisabled(element) {
  return canElementBeDisabled(element) && (isElementDisabled(element) || isAncestorDisabled(element));
}
function toBeDisabled(element) {
  (0, _utils.checkHtmlElement)(element, toBeDisabled, this);
  const isDisabled = isElementOrAncestorDisabled(element);
  return {
    pass: isDisabled,
    message: () => {
      const is = isDisabled ? "is" : "is not";
      return [this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toBeDisabled`, "element", ""), "", `Received element ${is} disabled:`, `  ${this.utils.printReceived(element.cloneNode(false))}`].join("\n");
    }
  };
}
function toBeEnabled(element) {
  (0, _utils.checkHtmlElement)(element, toBeEnabled, this);
  const isEnabled = !isElementOrAncestorDisabled(element);
  return {
    pass: isEnabled,
    message: () => {
      const is = isEnabled ? "is" : "is not";
      return [this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toBeEnabled`, "element", ""), "", `Received element ${is} enabled:`, `  ${this.utils.printReceived(element.cloneNode(false))}`].join("\n");
    }
  };
}
export {
  toBeDisabled$1 as default
};
//# sourceMappingURL=to-be-disabled.js.map
