/**
 * Unit tests for formatPhoneDisplay. Ported from webapp/js/contactHtml.test.js.
 */

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

describe("formatPhoneDisplay", () => {
  it("formats 11-digit number starting with 7", () => {
    expect(formatPhoneDisplay("79146522209")).toBe("+7 914 652-22-09");
    expect(formatPhoneDisplay("+79146522209")).toBe("+7 914 652-22-09");
  });

  it("formats 11-digit number starting with 8", () => {
    expect(formatPhoneDisplay("89146522209")).toBe("+7 914 652-22-09");
  });

  it("formats 10-digit number as Russian", () => {
    expect(formatPhoneDisplay("9146522209")).toBe("+7 914 652-22-09");
  });

  it("returns empty string for null or empty", () => {
    expect(formatPhoneDisplay(null)).toBe("");
    expect(formatPhoneDisplay("")).toBe("");
    expect(formatPhoneDisplay("  ")).toBe("");
  });

  it("strips non-digits before formatting", () => {
    expect(formatPhoneDisplay("+7 (914) 652-22-09")).toBe("+7 914 652-22-09");
  });

  it("returns digits as-is for non-10/11 length", () => {
    expect(formatPhoneDisplay("123")).toBe("123");
    expect(formatPhoneDisplay("12345678901")).toBe("12345678901");
  });
});
