import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:smplayer/core/infra/player_engine/player_engine.dart';
import 'package:smplayer/features/player/widgets/track_selector_button.dart';

import '../../../helpers/fake_player_engine.dart';

void main() {
  testWidgets('音轨按钮由初始 tracks 决定显隐', (tester) async {
    final player = FakePlayerEngine(
      playing: true,
      tracks: const PlayerTracks(
        audio: [
          AudioTrack(id: '1'),
          AudioTrack(id: '2'),
        ],
      ),
    );
    addTearDown(player.dispose);

    await tester.pumpWidget(
      MaterialApp(
        home: AudioTracksButton(
          player: player,
          isPanelOpen: false,
          onTogglePanel: () {},
        ),
      ),
    );

    expect(find.byTooltip('音轨'), findsOneWidget);
  });

  testWidgets('字幕按钮响应 tracks stream 更新', (tester) async {
    final player = FakePlayerEngine(playing: true);
    addTearDown(player.dispose);

    await tester.pumpWidget(
      MaterialApp(
        home: SubtitleTracksButton(
          player: player,
          embySubtitles: const [],
          isPanelOpen: false,
          onTogglePanel: () {},
        ),
      ),
    );
    expect(find.byTooltip('字幕'), findsNothing);

    player.addTracks(
      const PlayerTracks(subtitle: [SubtitleTrack(id: 'embedded')]),
    );
    await tester.pump();

    expect(find.byTooltip('字幕'), findsOneWidget);
  });
}
