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

import 'package:lanebow/models/event_model.dart';
import 'package:lanebow/models/club_model.dart';
import 'package:lanebow/screens/club/event_details_screen.dart';
import 'package:lanebow/services/event_service.dart';
import 'package:lanebow/services/club_service.dart';
import 'package:lanebow/services/member_service.dart';

import '../../utils/mock_services.dart';

import '../../utils/stub_event_service.dart';

void main() {
  testWidgets('EventDetailsScreen AppBar duplicate action clones and pops with true', (tester) async {
    // Arrange
    final stub = StubEventService();
    final event = Event(
      id: 'e1',
      clubId: 'club1',
      title: '테스트 이벤트',
      startDate: DateTime(2025, 1, 1),
      status: 'active',
      isActive: true,
    );

    final mockClub = MockClubService(club: Club(
      id: 'club1',
      name: '클럽',
      createdAt: DateTime.now(),
      updatedAt: DateTime.now(),
    ));
    final mockMembers = MockMemberService(seed: const []);

    await tester.pumpWidget(
      MultiProvider(
        providers: [
          ChangeNotifierProvider<EventService>.value(value: stub),
          ChangeNotifierProvider<ClubService>.value(value: mockClub),
          ChangeNotifierProvider<MemberService>.value(value: mockMembers),
        ],
        child: MaterialApp(
          home: EventDetailsScreen(event: event),
        ),
      ),
    );

    await tester.pumpAndSettle();

    // Act: tap duplicate icon button on AppBar
    final dupBtn = find.byIcon(Icons.copy);
    expect(dupBtn, findsOneWidget);
    await tester.tap(dupBtn);
    await tester.pumpAndSettle();

    // Assert: cloneEvent invoked on service
    expect(stub.lastCloneCalled, isTrue);
    expect(stub.lastClonedEventId, equals('e1'));
  });
}
