import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/pages/onboarding.dart';
import 'package:anyway/structs/trip.dart';
import 'package:anyway/utils/load_trips.dart';
import 'package:flutter/material.dart';

Widget getFirstPage() {
  SavedTrips trips = SavedTrips();
  trips.loadTrips();

  return ListenableBuilder(
    listenable: trips,
    builder: (BuildContext context, Widget? child) {
      List<Trip> items = trips.trips;
      if (items.isNotEmpty) {
        return TripPage(trip: items[0]);
      } else {
        return OnboardingPage();
      }
    }
  );
  // Future<List<Trip>> trips = loadTrips();
  // // test if there are any active trips
  // // if there are, return the trip list
  // // if there are not, return the onboarding page
  // return FutureBuilder(
  //   future: trips,
  //   builder: (context, snapshot) {
  //     if (snapshot.hasData) {
  //       List<Trip> availableTrips = snapshot.data!;
  //       if (availableTrips.isNotEmpty) {
  //         return TripPage(trip: availableTrips[0]);
  //       } else {
  //         return OnboardingPage();
  //       }
  //     } else {
  //       return CircularProgressIndicator();
  //     }
  //   }
  // );
}