// Proves the pen-first slide export geometry: contain-fit centering and the
// normalized->slide point mapping that replaces the old misaligned exporter.

import 'dart:ui' show Rect, Size;

import 'package:flutter_test/flutter_test.dart';

import 'package:badnote/editor/pdf/slide_export.dart';

void main() {
  test('wide image is letterboxed top/bottom on a square page', () {
    final r = slideDrawRect(const Size(1000, 1000), const Size(1600, 900));
    // scale = min(1000/1600, 1000/900) = 0.625 -> 1000 x 562.5, centered.
    expect(r.width, closeTo(1000, 1e-6));
    expect(r.height, closeTo(562.5, 1e-6));
    expect(r.left, closeTo(0, 1e-6));
    expect(r.top, closeTo((1000 - 562.5) / 2, 1e-6));
  });

  test('tall image is pillarboxed left/right', () {
    final r = slideDrawRect(const Size(1000, 1000), const Size(900, 1600));
    expect(r.height, closeTo(1000, 1e-6));
    expect(r.width, closeTo(562.5, 1e-6));
    expect(r.top, closeTo(0, 1e-6));
    expect(r.left, closeTo((1000 - 562.5) / 2, 1e-6));
  });

  test('normalized corners map to the draw rect corners', () {
    final r = const Rect.fromLTWH(100, 50, 800, 600);
    final tl = normToSlide(0, 0, r);
    final br = normToSlide(1, 1, r);
    final mid = normToSlide(0.5, 0.5, r);
    expect(tl.dx, closeTo(100, 1e-9));
    expect(tl.dy, closeTo(50, 1e-9));
    expect(br.dx, closeTo(900, 1e-9));
    expect(br.dy, closeTo(650, 1e-9));
    expect(mid.dx, closeTo(500, 1e-9));
    expect(mid.dy, closeTo(350, 1e-9));
  });

  test('stroke width scales with the draw width', () {
    final r = const Rect.fromLTWH(0, 0, 800, 600);
    expect(slideStrokeWidth(0.01, r), closeTo(8, 1e-9));
  });
}
