import 'package:flutter/material.dart';
import 'package:hl_lieferservice/model/delivery.dart';

import 'delivery_item.dart';

class DeliveryList extends StatefulWidget {
  final List<Delivery> deliveries;
  final Map<String, double> distances;

  const DeliveryList({
    super.key,
    required this.deliveries,
    required this.distances,
  });

  @override
  State<StatefulWidget> createState() => _DeliveryListState();
}

class _DeliveryListState extends State<DeliveryList> {
  @override
  Widget build(BuildContext context) {
    if (widget.deliveries.isEmpty) {
      return ListView(
        children: [Center(child: const Text("Keine Auslieferungen gefunden"))],
      );
    }

    return ListView.separated(
      separatorBuilder: (context, index) => const Divider(height: 0),
      itemBuilder: (context, index) {
        Delivery delivery = widget.deliveries[index];
        return DeliveryListItem(
          delivery: delivery,
          distance: widget.distances[delivery.id]!,
        );
      },
      itemCount: widget.deliveries.length,
    );
  }
}
