import { __exports as toHaveStyle$1 } from "../../../../_virtual/to-have-style.js";
import { i as interopRequireDefaultExports } from "../../../@babel/runtime/helpers/interopRequireDefault.js";
import { __require as requireSource } from './../_node_modules/chalk/source/index.js';
import "./utils.js";
import { __exports as utils } from "../../../../_virtual/utils.js";
var _interopRequireDefault = interopRequireDefaultExports;
Object.defineProperty(toHaveStyle$1, "__esModule", {
  value: true
});
toHaveStyle$1.toHaveStyle = toHaveStyle;
var _chalk = _interopRequireDefault(requireSource());
var _utils = utils;
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");
    }
  };
}
export {
  toHaveStyle$1 as default
};
//# sourceMappingURL=to-have-style.js.map
