import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:chanora_flutter/src/rust/api.dart' as rust;
import 'package:chanora_flutter/widgets/voice_settings_controls.dart';

void main() {
  test('shared transmit mode segments expose all modes', () {
    expect(transmitModeSegments.map((s) => s.value), [
      rust.BridgeTransmitMode.ptt,
      rust.BridgeTransmitMode.continuous,
      rust.BridgeTransmitMode.voiceActivity,
    ]);
  });

  test('shared Android processing segments expose hardware and WebRTC', () {
    expect(androidProcessingSegments.map((s) => s.value), [true, false]);
  });

  test('shared VAD segments expose supported non-disabled backends', () {
    expect(vadBackendSegments.map((s) => s.value), [
      rust.BridgeVadBackend.webrtcVad,
      rust.BridgeVadBackend.sileroOnnx,
    ]);
  });

  test('desktop VAD segments expose Silero as the primary backend', () {
    expect(desktopVadBackendSegments.map((s) => s.value), [
      rust.BridgeVadBackend.sileroOnnx,
    ]);
  });

  testWidgets('shared segmented style applies compact visual density', (
    tester,
  ) async {
    await tester.pumpWidget(
      MaterialApp(
        home: Builder(
          builder: (context) {
            final style = voiceSegmentedButtonStyle(Theme.of(context));
            return SegmentedButton<bool>(
              style: style,
              segments: androidProcessingSegments,
              selected: const {true},
            );
          },
        ),
      ),
    );

    expect(find.byType(SegmentedButton<bool>), findsOneWidget);
  });

  testWidgets('audio processing toggle row renders dense layout', (
    tester,
  ) async {
    var value = false;
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: StatefulBuilder(
            builder: (context, setState) {
              return AudioProcessingToggleRow(
                dense: true,
                label: 'Noise suppression',
                subtitle: 'Wiener filter',
                value: value,
                onChanged: (next) => setState(() => value = next),
              );
            },
          ),
        ),
      ),
    );

    await tester.tap(find.byType(Switch));
    await tester.pump();

    expect(value, isTrue);
    expect(find.text('Noise suppression'), findsOneWidget);
    expect(find.text('Wiener filter'), findsOneWidget);
  });
}
