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

import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/structs/trip.dart';


class CurrentTripGreeter extends StatefulWidget {
  final Trip trip;

  const CurrentTripGreeter({
    super.key,
    required this.trip,
  });

  @override
  State<CurrentTripGreeter> createState() => _CurrentTripGreeterState();
}


class _CurrentTripGreeterState extends State<CurrentTripGreeter> {
  @override
  Widget build(BuildContext context) => Center(
    child: FutureBuilder(
      future: widget.trip.cityName,
      builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
        if (snapshot.hasData) {
          return AutoSizeText(
            maxLines: 1,
            'Welcome to ${snapshot.data}!',
            style: greeterStyle
          );
        } else if (snapshot.hasError) {
          return AutoSizeText(
            maxLines: 1,
            'Welcome to your trip!',
            style: greeterStyle
          );
        } else {
          return AutoSizeText(
            maxLines: 1,
            'Welcome to ...',
            style: greeterStyle
          );
        }
      }
    )
  );

}
