import 'package:anyway/constants.dart';
import 'package:anyway/modules/current_trip_error_message.dart';
import 'package:anyway/modules/current_trip_loading_indicator.dart';
import 'package:flutter/material.dart';

import 'package:anyway/structs/trip.dart';
import 'package:anyway/modules/current_trip_summary.dart';
import 'package:anyway/modules/current_trip_save_button.dart';
import 'package:anyway/modules/current_trip_landmarks_list.dart';
import 'package:anyway/modules/current_trip_greeter.dart';


class CurrentTripPanel extends StatefulWidget {
  final ScrollController controller;
  final Trip trip;

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

  @override
  State<CurrentTripPanel> createState() => _CurrentTripPanelState();
}

class _CurrentTripPanelState extends State<CurrentTripPanel> {
  @override
  Widget build(BuildContext context) {
    return ListenableBuilder(
      listenable: widget.trip,
      builder: (context, child) {
        if (widget.trip.uuid == 'error') {
          return Align(
              alignment: Alignment.topCenter,
              child: SizedBox(
                // reuse the exact same height as the panel has when collapsed
                // this way the greeter will be centered when the panel is collapsed
                height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT - 20,
                child: CurrentTripErrorMessage(trip: widget.trip)
              ),
            );
        } else if (widget.trip.uuid == 'pending') {
            return Align(
              alignment: Alignment.topCenter,
              child: SizedBox(
                // reuse the exact same height as the panel has when collapsed
                // this way the greeter will be centered when the panel is collapsed
                height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT - 20,
                child: CurrentTripLoadingIndicator(trip: widget.trip),
              ),
            );
        } else {
          return ListView(
            controller: widget.controller,
            padding: const EdgeInsets.only(bottom: 30),
            children: [
              SizedBox(
                // reuse the exact same height as the panel has when collapsed
                // this way the greeter will be centered when the panel is collapsed
                height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT - 20,
                child: CurrentTripGreeter(trip: widget.trip),
              ),

              const Padding(padding: EdgeInsets.only(top: 10)),

              // CurrentTripSummary(trip: widget.trip),

              // const Divider(),

              ...landmarksList(widget.trip),

              const Padding(padding: EdgeInsets.only(top: 10)),

              Center(child: saveButton(widget.trip)),
            ],
          );
        }
      }
    );
  }
}