import { getInitialCropForGuidance, type GuidanceType } from '../types';

describe('getInitialCropForGuidance', () => {
  it('returns undefined for "none" guidance type', () => {
    expect(getInitialCropForGuidance('none')).toBeUndefined();
  });

  it('returns centered 85%-width crop with 6:1 AR for VIN', () => {
    const crop = getInitialCropForGuidance('vin');
    expect(crop).toBeDefined();
    if (!crop) return;
    expect(crop.width).toBe(85);
    expect(crop.height).toBeCloseTo(85 / 6, 1);
    expect(crop.x).toBeCloseTo((100 - 85) / 2, 1);
    expect(crop.y).toBeCloseTo((100 - 85 / 6) / 2, 1);
  });

  it('returns centered 70%-height crop with 2:3 AR for receipt', () => {
    const crop = getInitialCropForGuidance('receipt');
    expect(crop).toBeDefined();
    if (!crop) return;
    const expectedWidth = 70 * (2 / 3);
    expect(crop.height).toBe(70);
    expect(crop.width).toBeCloseTo(expectedWidth, 1);
    expect(crop.x).toBeCloseTo((100 - expectedWidth) / 2, 1);
    expect(crop.y).toBeCloseTo((100 - 70) / 2, 1);
  });

  it('returns centered 70%-height crop with 8.5:11 AR for document', () => {
    const crop = getInitialCropForGuidance('document');
    expect(crop).toBeDefined();
    if (!crop) return;
    const expectedWidth = 70 * (8.5 / 11);
    expect(crop.height).toBe(70);
    expect(crop.width).toBeCloseTo(expectedWidth, 1);
    expect(crop.x).toBeCloseTo((100 - expectedWidth) / 2, 1);
    expect(crop.y).toBeCloseTo((100 - 70) / 2, 1);
  });

  it('returns crop areas within 0-100 bounds for all types', () => {
    (['vin', 'receipt', 'document'] as GuidanceType[]).forEach((type) => {
      const crop = getInitialCropForGuidance(type);
      expect(crop).toBeDefined();
      if (!crop) return;
      expect(crop.x).toBeGreaterThanOrEqual(0);
      expect(crop.y).toBeGreaterThanOrEqual(0);
      expect(crop.width).toBeGreaterThanOrEqual(0);
      expect(crop.height).toBeGreaterThanOrEqual(0);
      expect(crop.x + crop.width).toBeLessThanOrEqual(100);
      expect(crop.y + crop.height).toBeLessThanOrEqual(100);
    });
  });
});
