import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    return _buildTable("Bus Booking List", _getBusData());
  }

  List<Map<String, String>> _getBusData() {
    return [
      {"tripType": "One-Way", "class": "Economy", "from": "NYC", "to": "LA"},
      {"tripType": "Round-Trip", "class": "Business", "from": "SF", "to": "Seattle"},
    ];
  }
}

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

  @override
  Widget build(BuildContext context) {
    return _buildTable("Train Booking List", _getTrainData());
  }

  List<Map<String, String>> _getTrainData() {
    return [
      {"tripType": "Express", "class": "Sleeper", "from": "Chicago", "to": "Boston"},
      {"tripType": "Local", "class": "First-Class", "from": "Houston", "to": "Dallas"},
    ];
  }
}

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

  @override
  Widget build(BuildContext context) {
    return _buildTable("Taxi Booking List", _getTaxiData());
  }

  List<Map<String, String>> _getTaxiData() {
    return [
      {"tripType": "City Ride", "class": "Sedan", "from": "Manhattan", "to": "Brooklyn"},
      {"tripType": "Airport Transfer", "class": "SUV", "from": "JFK", "to": "Times Square"},
    ];
  }
}

// ✅ Reusable function for building DataTable
Widget _buildTable(String title, List<Map<String, String>> data) {
  return Padding(
    padding: const EdgeInsets.all(16.0),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(title, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
        const SizedBox(height: 16),
        SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: DataTable(
            border: TableBorder(
              top: BorderSide(color: Colors.black12),
              bottom: BorderSide(color: Colors.black12),
              horizontalInside: BorderSide(color: Colors.black12), // Only horizontal borders
            ),
            columns: const [
              DataColumn(label: Text('Trip Type')),
              DataColumn(label: Text('Class')),
              DataColumn(label: Text('From')),
              DataColumn(label: Text('To')),
              DataColumn(label: Text('Actions')),
            ],
            rows: data.map((item) {
              return DataRow(cells: [
                DataCell(Text(item["tripType"]!)),
                DataCell(Text(item["class"]!)),
                DataCell(Text(item["from"]!)),
                DataCell(Text(item["to"]!)),
                DataCell(Row(
                  children: [
                    IconButton(
                      icon: Icon(Icons.remove_red_eye, color: Colors.blue),
                      onPressed: () {
                        // View action
                      },
                    ),
                    IconButton(
                      icon: Icon(Icons.edit, color: Colors.green),
                      onPressed: () {
                        // Edit action
                      },
                    ),
                    IconButton(
                      icon: Icon(Icons.delete, color: Colors.red),
                      onPressed: () {
                        // Delete action
                      },
                    ),
                  ],
                )),
              ]);
            }).toList(),
          ),
        ),
      ],
    ),
  );
}
