"use strict";
const toHaveAttribute$1 = require("../../../../_virtual/to-have-attribute.cjs");
require("./utils.cjs");
const utils = require("../../../../_virtual/utils.cjs");
Object.defineProperty(toHaveAttribute$1.__exports, "__esModule", {
  value: true
});
toHaveAttribute$1.__exports.toHaveAttribute = toHaveAttribute;
var _utils = utils.__exports;
function printAttribute(stringify, name, value) {
  return value === void 0 ? name : `${name}=${stringify(value)}`;
}
function getAttributeComment(stringify, name, value) {
  return value === void 0 ? `element.hasAttribute(${stringify(name)})` : `element.getAttribute(${stringify(name)}) === ${stringify(value)}`;
}
function toHaveAttribute(htmlElement, name, expectedValue) {
  (0, _utils.checkHtmlElement)(htmlElement, toHaveAttribute, this);
  const isExpectedValuePresent = expectedValue !== void 0;
  const hasAttribute = htmlElement.hasAttribute(name);
  const receivedValue = htmlElement.getAttribute(name);
  return {
    pass: isExpectedValuePresent ? hasAttribute && this.equals(receivedValue, expectedValue) : hasAttribute,
    message: () => {
      const to = this.isNot ? "not to" : "to";
      const receivedAttribute = hasAttribute ? printAttribute(this.utils.stringify, name, receivedValue) : null;
      const matcher = this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveAttribute`, "element", this.utils.printExpected(name), {
        secondArgument: isExpectedValuePresent ? this.utils.printExpected(expectedValue) : void 0,
        comment: getAttributeComment(this.utils.stringify, name, expectedValue)
      });
      return (0, _utils.getMessage)(this, matcher, `Expected the element ${to} have attribute`, printAttribute(this.utils.stringify, name, expectedValue), "Received", receivedAttribute);
    }
  };
}
module.exports = toHaveAttribute$1.__exports;
//# sourceMappingURL=to-have-attribute.cjs.map
