import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lanebow/screens/public_event/public_event_screen.dart';
import 'package:lanebow/services/public_event_service.dart';

class StubColorService extends PublicEventService {
  @override
  Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
    return {
      'event': {'id': 'E1', 'title': '색상/상태 테스트', 'gameCount': 3, 'status': 'active'},
      'participants': [
        {
          'participantId': 'p1',
          'name': 'Kim',
          'scores': [null, null, null],
          'handicap': 0,
        },
      ],
      'teams': [],
    };
  }

  @override
  Future<void> updateScore(String publicHash, {required String participantId, required int gameNumber, required int score, int? handicap, teamNumber}) async {
    // no-op
    await Future<void>.delayed(const Duration(milliseconds: 1));
  }
}

void main() {
  testWidgets('200 입력 시 색상 빨강으로 표시', (tester) async {
    await tester.pumpWidget(MaterialApp(
      home: PublicEventScreen(publicHash: 'H', service: StubColorService()),
    ));
    await tester.pumpAndSettle();

    // 초기에는 회색 점
    final colorDot = find.byKey(const Key('color_p1_1'));
    expect(colorDot, findsOneWidget);

    // 200 입력
    final cell = find.byKey(const Key('cell_p1_1'));
    await tester.enterText(cell, '200');
    await tester.pump(const Duration(milliseconds: 20));

    // 색상 컨테이너를 가져와서 색상을 확인
    final container = tester.widget<Container>(colorDot);
    final deco = container.decoration as BoxDecoration;
    expect((deco.color as Color), equals(Colors.red));
  });
}
