import {
  formatMobileForDisplay,
  isValidMobile,
  mobileSearchDigits,
  normalizeMobile,
} from './phone';

describe('normalizeMobile', () => {
  it('normalizes 09-prefixed numbers', () => {
    expect(normalizeMobile('09121234567')).toBe('+989121234567');
  });

  it('normalizes without leading zero', () => {
    expect(normalizeMobile('9121234567')).toBe('+989121234567');
  });

  it('normalizes +98 prefix', () => {
    expect(normalizeMobile('+989121234567')).toBe('+989121234567');
  });

  it('normalizes 0098 prefix', () => {
    expect(normalizeMobile('00989121234567')).toBe('+989121234567');
  });

  it('normalizes spaced input', () => {
    expect(normalizeMobile('0912 123 4567')).toBe('+989121234567');
  });

  it('rejects invalid numbers', () => {
    expect(normalizeMobile('123')).toBeNull();
    expect(normalizeMobile('')).toBeNull();
  });
});

describe('isValidMobile', () => {
  it('validates normalized mobile', () => {
    expect(isValidMobile('+989121234567')).toBe(true);
    expect(isValidMobile('09121234567')).toBe(false);
  });
});

describe('formatMobileForDisplay', () => {
  it('formats E.164 to local spaced form', () => {
    expect(formatMobileForDisplay('+989121234567')).toBe('0912 123 4567');
  });
});

describe('mobileSearchDigits', () => {
  it('strips non-digits', () => {
    expect(mobileSearchDigits('+98 912-123-4567')).toBe('989121234567');
  });
});
