"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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 __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = __toESM(require("react"));
var import_react2 = require("@testing-library/react");
var import__ = require("../..");
const numbersFormats = [
  {
    country: "BR",
    base: "+5511959112508",
    expected: "+55 (11) 959112508"
  },
  {
    country: "US",
    base: "+12025550134",
    expected: "+1 (202) 555-0134"
  },
  {
    country: "PT",
    base: "+351911803423",
    expected: "+351 911 803 423"
  }
];
describe("<Input.Phone />", () => {
  describe("Snapshots", () => {
    it("should match with default input", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Phone, {}) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with disabled input", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Password, { disabled: true }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with error", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { error: "Error message" }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with full width", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Password, { label: "Label", full: true }) })
      );
      expect(container).toMatchSnapshot();
    });
  });
  describe("Behaviour", () => {
    numbersFormats.forEach((spec) => {
      it(`Should render number in ${spec.country} format according to phone value`, () => {
        const { getByDisplayValue } = (0, import_react2.render)(
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Phone, { value: spec.base }) })
        );
        expect(getByDisplayValue(spec.expected)).toBeInTheDocument();
      });
    });
    it(`Should only format and show countries numbers when props is given`, () => {
      const USPhone = numbersFormats[1];
      const { queryByDisplayValue } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Phone, { countries: ["br", "pt"], value: USPhone.base }) })
      );
      expect(queryByDisplayValue(USPhone.expected)).not.toBeInTheDocument();
    });
    it(`Should return all countries validation if countries equals to empty array`, () => {
      const USPhone = numbersFormats[1];
      const { getAllByRole } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Phone, { countries: [], value: USPhone.base }) })
      );
      import_react2.fireEvent.click(getAllByRole("button")[0]);
      expect(getAllByRole("option").length).toBe(13);
    });
    it(`Should call onblur event`, () => {
      const USPhone = numbersFormats[1];
      const onBlur = jest.fn();
      const { getAllByRole } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Phone, { onBlur, countries: [], value: USPhone.base }) })
      );
      const inputPhone = getAllByRole("textbox")[0];
      import_react2.fireEvent.blur(inputPhone);
      expect(onBlur).toHaveBeenCalled();
    });
    it("should prefix the phone number with newly selected country dial code", () => __async(exports, null, function* () {
      const { getByRole, getByText, getByDisplayValue } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input.Phone, { defaultCountry: "us" }) })
      );
      yield (0, import_react2.waitFor)(() => {
        import_react2.fireEvent.click(getByRole("button"));
        import_react2.fireEvent.click(getByText("Portugal"));
      });
      expect(getByDisplayValue("+351")).toBeInTheDocument();
    }));
  });
});
