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

import 'package:chanora_flutter/services/link_trust_service.dart';
import 'package:chanora_flutter/services/ts3_server_link.dart';
import 'package:chanora_flutter/widgets/bbcode_text.dart';

void main() {
  setUp(() {
    SharedPreferences.setMockInitialValues({});
  });

  testWidgets('renders links without underline decoration', (tester) async {
    await tester.pumpWidget(
      MaterialApp(
        home: BbCodeText(
          'https://example.com',
          linkTrust: LinkTrustService.instance,
        ),
      ),
    );

    final linkText = tester.widget<Text>(find.text('https://example.com'));
    expect(linkText.style?.color, Colors.blue);
    expect(linkText.style?.decoration, isNull);
  });

  testWidgets('handles TeamSpeak server links without browser launch', (
    tester,
  ) async {
    Ts3ServerLink? tapped;

    await tester.pumpWidget(
      MaterialApp(
        home: BbCodeText(
          'ts3server://teamspeak.app%3Faddbookmark%3DVigorous%20Pro/',
          linkTrust: LinkTrustService.instance,
          onTs3ServerLink: (link) async => tapped = link,
        ),
      ),
    );

    await tester.tap(
      find.text('ts3server://teamspeak.app%3Faddbookmark%3DVigorous%20Pro/'),
    );
    await tester.pump();

    expect(tapped, isNotNull);
    expect(tapped!.host, 'teamspeak.app');
    expect(tapped!.addBookmark, 'Vigorous Pro');
  });
}
