"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = __toESM(require("react"));
var import_react2 = require("@testing-library/react");
var import__ = require("../..");
var import__2 = __toESM(require("."));
describe("<Rating />", () => {
  const originalOffsetWidth = Object.getOwnPropertyDescriptor(
    HTMLElement.prototype,
    "offsetWidth"
  );
  beforeAll(() => {
    Object.defineProperty(HTMLElement.prototype, "offsetWidth", {
      configurable: true,
      value: 76
      // 5 stars (5 * 12px + 4 * 4px gutter)
    });
  });
  afterAll(() => {
    Object.defineProperty(
      HTMLElement.prototype,
      "offsetWidth",
      originalOffsetWidth
    );
  });
  describe("Snapshots", () => {
    it("should match snapshot with Rating", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, {}) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot with different values", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import__.ThemeProvider, { children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 0 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 0.5 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.1 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.2 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.3 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.4 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.5 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.6 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.7 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.8 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 1.9 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 2 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 2.5 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 3 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 3.5 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 4 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { value: 4.5 })
        ] })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot with different icon quantity", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import__.ThemeProvider, { children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { max: 3, value: 0 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { max: 3, value: 0.5 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { max: 3, value: 1 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { max: 3, value: 1.5 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { max: 3, value: 2 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { max: 3, value: 2.5 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { max: 3, value: 3 })
        ] })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot with different icon", () => {
      const Circle = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "12" }) }));
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import__.ThemeProvider, { children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { icon: { type: Circle }, value: 0 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { icon: { type: Circle }, value: 1 }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { icon: { type: Circle }, value: 2 })
        ] })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot when mouse over", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { readOnly: false }) })
      );
      const { firstChild } = container;
      import_react2.fireEvent.mouseMove(firstChild, {
        /** Each star has 12px. Gutter is 4px.
         * For the third star, we should set clentX > 32px and < 48px */
        clientX: 40
      });
      expect(container).toMatchSnapshot();
    });
  });
  describe("Events", () => {
    it("should call onRate when clicking", () => {
      const onRateMock = jest.fn();
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { onRate: onRateMock, readOnly: false }) })
      );
      const { firstChild } = container;
      import_react2.fireEvent.mouseMove(firstChild, {
        clientX: 40
        // third star position
      });
      import_react2.fireEvent.click(firstChild);
      expect(onRateMock).toHaveBeenCalled();
      expect(onRateMock).toHaveBeenCalledWith(3);
    });
    it("should call onMouseOver callback", () => {
      const onMouseOverMock = jest.fn();
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { onMouseOver: onMouseOverMock, readOnly: false }) })
      );
      const { firstChild } = container;
      import_react2.fireEvent.mouseOver(firstChild);
      expect(onMouseOverMock).toHaveBeenCalled();
    });
    it("should call onMouseLeave callback", () => {
      const onMouseLeaveMock = jest.fn();
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__2.default, { onMouseLeave: onMouseLeaveMock, readOnly: false }) })
      );
      const { firstChild } = container;
      import_react2.fireEvent.mouseLeave(firstChild);
      expect(onMouseLeaveMock).toHaveBeenCalled();
    });
  });
});
