import 'package:flutter/material.dart';
import 'package:em2rp/models/event_model.dart';
import 'package:em2rp/utils/colors.dart';
import 'package:intl/intl.dart';

class EventDetailsNavigation extends StatelessWidget {
  final List<EventModel> sortedEvents;
  final int currentIndex;
  final DateTime? selectedDate;
  final void Function(EventModel, DateTime) onSelectEvent;

  const EventDetailsNavigation({
    super.key,
    required this.sortedEvents,
    required this.currentIndex,
    required this.selectedDate,
    required this.onSelectEvent,
  });

  @override
  Widget build(BuildContext context) {
    final fullDateFormat = DateFormat('EEEE d MMMM y', 'fr_FR');

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        IconButton(
          onPressed: currentIndex > 0
              ? () {
                  final prevEvent = sortedEvents[currentIndex - 1];
                  onSelectEvent(prevEvent, prevEvent.startDateTime);
                }
              : null,
          icon: const Icon(Icons.arrow_back),
          color: AppColors.rouge,
        ),
        if (selectedDate != null)
          Expanded(
            child: Center(
              child: Text(
                fullDateFormat.format(selectedDate!),
                style: Theme.of(context).textTheme.titleLarge?.copyWith(
                      color: AppColors.rouge,
                      fontWeight: FontWeight.bold,
                    ),
              ),
            ),
          ),
        IconButton(
          onPressed: currentIndex < sortedEvents.length - 1
              ? () {
                  final nextEvent = sortedEvents[currentIndex + 1];
                  onSelectEvent(nextEvent, nextEvent.startDateTime);
                }
              : null,
          icon: const Icon(Icons.arrow_forward),
          color: AppColors.rouge,
        ),
      ],
    );
  }
}

