import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:hl_lieferservice/feature/cars/bloc/cars_bloc.dart';
import 'package:hl_lieferservice/feature/cars/bloc/cars_event.dart';

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

  void _onRetry(BuildContext context) {
    context.read<CarsBloc>().add(const CarLoad(force: true));
  }

  @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,
            ),
            const Padding(
              padding: EdgeInsets.only(top: 30),
              child: Text(
                "Leider ist es beim Laden der Fahrzeuge zu einem Fehler gekommen.",
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 30),
              child: FilledButton(
                onPressed: () => _onRetry(context),
                child: const Text("Erneut versuchen"),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
