import 'package:equatable/equatable.dart'; import 'package:finlytic_app/features/calendar/models/corporate_event_model.dart'; abstract class CalendarState extends Equatable { const CalendarState(); @override List get props => []; } class CalendarInitial extends CalendarState {} class CalendarLoading extends CalendarState {} class CalendarLoaded extends CalendarState { final List allEvents; final String selectedCategory; final DateTime currentMonth; final DateTime? selectedDate; const CalendarLoaded({ required this.allEvents, this.selectedCategory = 'Alle', required this.currentMonth, this.selectedDate, }); static bool matchesCategory(String eventType, String category) { if (category == 'Alle' || category.isEmpty) return true; final catKey = category.toLowerCase(); final t = eventType.toLowerCase(); if (catKey.contains('earn') || catKey.contains('quartal') || catKey.contains('ergebnis')) { return t.contains('earn') || t.contains('quart') || t.contains('ergebnis') || t.contains('finan') || t.contains('report') || t.contains('bilanz') || t == 'event'; } if (catKey.contains('ex') || catKey.contains('div')) { return (t.contains('ex') || t.contains('div') || t.contains('ausschütt')) && !t.contains('pay') && !t.contains('zahl'); } if (catKey.contains('pay') || catKey.contains('zahl')) { return t.contains('pay') || t.contains('zahl') || t.contains('auszahl'); } if (catKey.contains('split')) { return t.contains('split'); } return t.contains(catKey) || t == catKey; } List get filteredEvents { return allEvents.where((e) { if (!matchesCategory(e.eventType, selectedCategory)) { return false; } if (selectedDate != null) { if (e.eventDate.year != selectedDate!.year || e.eventDate.month != selectedDate!.month || e.eventDate.day != selectedDate!.day) { return false; } } return true; }).toList(); } CalendarLoaded copyWith({ List? allEvents, String? selectedCategory, DateTime? currentMonth, DateTime? selectedDate, bool clearSelectedDate = false, }) { return CalendarLoaded( allEvents: allEvents ?? this.allEvents, selectedCategory: selectedCategory ?? this.selectedCategory, currentMonth: currentMonth ?? this.currentMonth, selectedDate: clearSelectedDate ? null : (selectedDate ?? this.selectedDate), ); } @override List get props => [allEvents, selectedCategory, currentMonth, selectedDate]; } class CalendarError extends CalendarState { final String message; const CalendarError(this.message); @override List get props => [message]; }