import { describe, it, expect } from "vitest";
import { formatPhone } from "./format-phone";

describe("formatPhone", () => {
  it("should return empty string when input is null, undefined, or empty", () => {
    expect(formatPhone(null)).toBe("");
    expect(formatPhone(undefined)).toBe("");
    expect(formatPhone("")).toBe("");
  });

  it("should format DDD (up to 2 digits)", () => {
    expect(formatPhone("1")).toBe("(1");
    expect(formatPhone("11")).toBe("(11");
  });

  it("should format partial numbers before dash", () => {
    expect(formatPhone("119")).toBe("(11) 9");
    expect(formatPhone("119862")).toBe("(11) 9862");
  });

  it("should format 10 digits (landline number)", () => {
    expect(formatPhone("1134567890")).toBe("(11) 3456-7890");
  });

  it("should format 11 digits (mobile number)", () => {
    expect(formatPhone("11986207471")).toBe("(11) 98620-7471");
  });

  it("should handle input that already has non-digit characters", () => {
    expect(formatPhone("(11) 98620-7471")).toBe("(11) 98620-7471");
    expect(formatPhone("+55 (11) 98620-7471")).toBe("(55) 11986-2074");
  });

  it("should limit maximum digits to 11", () => {
    expect(formatPhone("11986207471999")).toBe("(11) 98620-7471");
  });
});
