import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:recording_tool/features/recording/widgets/widget_recording_hud.dart';

void main() {
  Future<void> pumpHud(
    WidgetTester tester, {
    double zoomRatio = 1.0,
    double minZoomRatio = 1.0,
    double maxZoomRatio = 3.0,
    ValueChanged<double>? onZoomSelected,
  }) async {
    await tester.pumpWidget(
      ScreenUtilInit(
        designSize: const Size(375, 812),
        builder: (context, _) {
          return MaterialApp(
            home: Scaffold(
              backgroundColor: Colors.black,
              body: RecordingHudWidget(
                hasDndAccess: true,
                isBatteryOptimizedIgnored: true,
                notificationsGranted: true,
                isRecording: false,
                isStartingRecording: false,
                isTouchLocked: false,
                zoomRatio: zoomRatio,
                minZoomRatio: minZoomRatio,
                maxZoomRatio: maxZoomRatio,
                onStart: () async {},
                onStop: () async {},
                onOpenDnd: () {},
                onOpenBattery: () {},
                onToggleTouchLock: () {},
                onZoomSelected: onZoomSelected ?? (_) {},
              ),
            ),
          );
        },
      ),
    );
    await tester.pump();
  }

  testWidgets('shows preset zoom buttons', (tester) async {
    await pumpHud(tester);

    expect(find.text('1x'), findsOneWidget);
    expect(find.text('2x'), findsOneWidget);
    expect(find.text('3x'), findsOneWidget);
  });

  testWidgets('marks current zoom ratio as selected', (tester) async {
    await pumpHud(tester, zoomRatio: 2.0);

    final selectedButton = tester.widget<TextButton>(
      find.ancestor(of: find.text('2x'), matching: find.byType(TextButton)),
    );
    expect(selectedButton.enabled, isFalse);
  });

  testWidgets('does not expose presets beyond max zoom ratio', (tester) async {
    await pumpHud(tester, maxZoomRatio: 2.0);

    expect(find.text('1x'), findsOneWidget);
    expect(find.text('2x'), findsOneWidget);
    expect(find.text('3x'), findsNothing);
  });

  testWidgets('tapping zoom preset reports selected ratio', (tester) async {
    double? selected;
    await pumpHud(tester, onZoomSelected: (ratio) => selected = ratio);

    await tester.tap(find.text('2x'));
    await tester.pump();

    expect(selected, 2.0);
  });
}
