import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_state.dart';
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';

class DeliveryLoadingFailedPage extends StatelessWidget {
  const DeliveryLoadingFailedPage({super.key});

  void _onRetry(BuildContext context) {
    Authenticated state = context.read<AuthBloc>().state as Authenticated;
    context.read<TourBloc>().add(LoadTour(teamId: state.user.number));
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(50),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(Icons.error_outline, size: 72, color: Theme.of(context).colorScheme.error,),
            Padding(
              padding: const EdgeInsets.only(top: 30),
              child: Text(
                "Leider ist es beim Laden der Fahrten zu einem Fehler gekommen.",
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 30),
              child: FilledButton(
                onPressed: () => _onRetry(context),
                child: Text("Erneut versuchen"),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
