"use strict";
const toHaveStyle$1 = require("../../../../_virtual/to-have-style.cjs");
const interopRequireDefault = require("../../../@babel/runtime/helpers/interopRequireDefault.cjs");
const index = require('./../_node_modules/chalk/source/index.cjs');
require("./utils.cjs");
const utils = require("../../../../_virtual/utils.cjs");
var _interopRequireDefault = interopRequireDefault.interopRequireDefaultExports;
Object.defineProperty(toHaveStyle$1.__exports, "__esModule", {
  value: true
});
toHaveStyle$1.__exports.toHaveStyle = toHaveStyle;
var _chalk = _interopRequireDefault(index.__require());
var _utils = utils.__exports;
function getStyleDeclaration(document, css) {
  const styles = {};
  const copy = document.createElement("div");
  Object.keys(css).forEach((property) => {
    copy.style[property] = css[property];
    styles[property] = copy.style[property];
  });
  return styles;
}
function isSubset(styles, computedStyle) {
  return !!Object.keys(styles).length && Object.entries(styles).every(([prop, value]) => computedStyle[prop] === value || computedStyle.getPropertyValue(prop.toLowerCase()) === value);
}
function printoutStyles(styles) {
  return Object.keys(styles).sort().map((prop) => `${prop}: ${styles[prop]};`).join("\n");
}
function expectedDiff(diffFn, expected, computedStyles) {
  const received = Array.from(computedStyles).filter((prop) => expected[prop] !== void 0).reduce((obj, prop) => Object.assign(obj, {
    [prop]: computedStyles.getPropertyValue(prop)
  }), {});
  const diffOutput = diffFn(printoutStyles(expected), printoutStyles(received));
  return diffOutput.replace(`${_chalk.default.red("+ Received")}
`, "");
}
function toHaveStyle(htmlElement, css) {
  (0, _utils.checkHtmlElement)(htmlElement, toHaveStyle, this);
  const parsedCSS = typeof css === "object" ? css : (0, _utils.parseCSS)(css, toHaveStyle, this);
  const {
    getComputedStyle
  } = htmlElement.ownerDocument.defaultView;
  const expected = getStyleDeclaration(htmlElement.ownerDocument, parsedCSS);
  const received = getComputedStyle(htmlElement);
  return {
    pass: isSubset(expected, received),
    message: () => {
      const matcher = `${this.isNot ? ".not" : ""}.toHaveStyle`;
      return [this.utils.matcherHint(matcher, "element", ""), expectedDiff(this.utils.diff, expected, received)].join("\n\n");
    }
  };
}
module.exports = toHaveStyle$1.__exports;
//# sourceMappingURL=to-have-style.cjs.map
