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

void main() {
  testWidgets(
    'a csal\u00e1di napt\u00e1r f\u0151 n\u00e9zete bet\u00f6lt\u0151dik',
    (tester) async {
      await tester.binding.setSurfaceSize(const Size(1200, 800));
      await tester.pumpWidget(const OtthonApp());

      expect(find.byType(CalendarPage), findsOneWidget);
      expect(find.byType(PageFrame), findsOneWidget);
    },
  );

  testWidgets('a csal\u00e1dtagok n\u00e9zet el\u00e9rhet\u0151', (
    tester,
  ) async {
    await tester.binding.setSurfaceSize(const Size(1200, 800));
    await tester.pumpWidget(const OtthonApp());
    await tester.tap(find.byIcon(Icons.group_outlined));
    await tester.pumpAndSettle();

    expect(find.byType(PersonsPage), findsOneWidget);
  });

  testWidgets(
    'a st\u00edlus n\u00e9zet \u00e9s avatar k\u00e9szlet el\u00e9rhet\u0151',
    (tester) async {
      await tester.binding.setSurfaceSize(const Size(1200, 800));
      await tester.pumpWidget(const OtthonApp());
      await tester.tap(find.byIcon(Icons.palette_outlined));
      await tester.pumpAndSettle();

      expect(find.byType(StylePage), findsOneWidget);
    },
  );

  testWidgets(
    'az eszk\u00f6z napt\u00e1rkapcsolatok oldala el\u00e9rhet\u0151',
    (tester) async {
      await tester.binding.setSurfaceSize(const Size(1200, 800));
      await tester.pumpWidget(const OtthonApp());
      await tester.tap(find.byIcon(Icons.sync_rounded));
      await tester.pumpAndSettle();

      expect(find.byType(AccountsPage), findsOneWidget);
    },
  );

  test(
    'a csal\u00e1dtag k\u00f6vetkez\u0151 esem\u00e9nyei csak m\u00e1t\u00f3l indulnak',
    () {
      final now = DateTime(2026, 7, 19, 15);
      final events = [
        CalendarEvent(
          'Tegnapi program',
          '10:00',
          '11:00',
          Colors.red,
          date: DateTime(2026, 7, 18),
          personId: 'balint',
        ),
        CalendarEvent(
          'Mai program',
          '09:00',
          '10:00',
          Colors.green,
          date: DateTime(2026, 7, 19),
          personId: 'balint',
        ),
        CalendarEvent(
          'Holnapi program',
          '08:00',
          '09:00',
          Colors.blue,
          date: DateTime(2026, 7, 20),
          personId: 'balint',
        ),
      ];

      final nextEvents = findNextEventsForPerson('balint', events, 3, now: now);

      expect(nextEvents.map((event) => event.title), [
        'Mai program',
        'Holnapi program',
      ]);
    },
  );

  test(
    'a mindenkihez tartoz\u00f3 esem\u00e9ny minden csal\u00e1dtagn\u00e1l megjelenik',
    () {
      final now = DateTime(2026, 7, 19, 15);
      final events = [
        CalendarEvent(
          'Csal\u00e1di program',
          '17:00',
          '18:00',
          Colors.green,
          date: DateTime(2026, 7, 20),
          personId: everyonePersonId,
        ),
      ];

      final balintEvents = findNextEventsForPerson(
        'balint',
        events,
        3,
        now: now,
      );
      final emiliaEvents = findNextEventsForPerson(
        'emilia',
        events,
        3,
        now: now,
      );

      expect(balintEvents.single.title, 'Csal\u00e1di program');
      expect(emiliaEvents.single.title, 'Csal\u00e1di program');
    },
  );
}
