import 'package:anyway/modules/current_trip_save_button.dart';
import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';

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



class TripPage extends StatefulWidget {
  final Trip trip;

  TripPage({
    required this.trip,
  });

  @override
  State<TripPage> createState() => _TripPageState();
}



class _TripPageState extends State<TripPage> {

  @override
  Widget build(BuildContext context) {
    return SlidingUpPanel(
        panelBuilder: (sc) => _panelFull(sc),
        // collapsed: _floatingCollapsed(),
        body: CurrentTripMap(trip: widget.trip),
        // renderPanelSheet: false,
        // backdropEnabled: true,
        maxHeight: MediaQuery.of(context).size.height * 0.8,
        padding: EdgeInsets.only(left: 10, right: 10, top: 25, bottom: 10),
        // panelSnapping: false,
        borderRadius: BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)),
        boxShadow: const [
          BoxShadow(
            blurRadius: 20.0,
            color: Colors.black,
          )
        ],
    );
  }

  
  Widget _panelFull(ScrollController sc) {
    return ListenableBuilder(
      listenable: widget.trip,
      builder: (context, child) {
        if (widget.trip.uuid != 'pending' && widget.trip.uuid != 'error') {
          return ListView(
            controller: sc,
            padding: EdgeInsets.only(bottom: 35),
            children: [
              Greeter(trip: widget.trip),
              ...landmarksList(widget.trip),
              Padding(padding: EdgeInsets.only(top: 10)),
              Center(child: saveButton(widget.trip)),
            ],
          );
        } else if(widget.trip.uuid == 'pending') {
          return Greeter(trip: widget.trip);
        } else {
          return Column(
            children: [
              const Icon(
                Icons.error_outline,
                color: Colors.red,
                size: 60,
              ),
              Padding(
                padding: const EdgeInsets.only(top: 16),
                child: Text('Error: ${widget.trip.errorDescription}'),
              ),
            ],
          );
        }
      }
    );
  }
}
