import 'package:flutter/material.dart';

import '../model/flood_station.dart';

class FloodStationListView extends StatelessWidget {
  const FloodStationListView(
      {super.key,
      required List<FloodStation> stations,
      required void Function(FloodStation) onItemTapped})
      : _onItemTapped = onItemTapped,
        _stations = stations;

  final List<FloodStation> _stations;
  final void Function(FloodStation) _onItemTapped;

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      separatorBuilder: (context, index) => Padding(
        padding: const EdgeInsets.symmetric(horizontal: 15.0),
        child: Divider(),
      ),
      itemBuilder: (context, index) {
        final item = _stations.elementAt(index);
        return ListTile(
          isThreeLine: true,
          onTap: () => _onItemTapped(item),
          title: Text(item.label),
          subtitle: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(Icons.home_outlined),
                  Padding(padding: EdgeInsets.only(left: 8)),
                  Text(item.town),
                ],
              ),
              Row(
                children: [
                  Icon(Icons.water),
                  Padding(padding: EdgeInsets.only(left: 8)),
                  Text(item.riverName),
                ],
              )
            ],
          ),
        );
      },
      itemCount: _stations.length,
    );
  }
}
