import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
import 'package:geocode/geocode.dart';
import 'dart:async';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import 'package:fast_network_navigation/modules/navigation.dart';
import 'package:fast_network_navigation/modules/map.dart';



class MainPage extends StatefulWidget {
  @override
  State<MainPage> createState() => _MainPageState();
}



class Debounce {
  Duration delay;
  Timer? _timer;

  Debounce(
    this.delay,
  );

  call(void Function() callback) {
    _timer?.cancel();
    _timer = Timer(delay, callback);
  }

  dispose() {
    _timer?.cancel();
  }
}


class _MainPageState extends State<MainPage> {

  @override
  Widget build(BuildContext context) {
    final ThemeData theme = Theme.of(context);
    return SlidingUpPanel(
        renderPanelSheet: false,
        panel: _floatingPanel(theme),
        collapsed: _floatingCollapsed(theme),
        body: MapWidget()
    );
  }

  Widget _floatingCollapsed(ThemeData theme){
    return Container(
      decoration: BoxDecoration(
        color: theme.canvasColor,
        borderRadius: BorderRadius.only(topLeft: Radius.circular(24.0), topRight: Radius.circular(24.0)),
      ),
      
      child: Greeting(theme)
    );
  }

  Widget _floatingPanel(ThemeData theme){
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(24.0)),
        boxShadow: [
          BoxShadow(
            blurRadius: 20.0,
            color: theme.shadowColor,
          ),
        ]
      ),
      child: Center(
        child: Padding(
        padding: EdgeInsets.all(8.0),
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Greeting(theme),
              Text("Got a lot to do today! Here is a rundown:"),
              ...loadDestinations(),
            ],
          ),
        ),
      ),
    ),
    );
  }

  Widget Greeting (ThemeData theme) {
    return Center(
        child: Text(
            "Explore #todo",
          style: TextStyle(color: theme.primaryColor, fontSize: 24.0, fontWeight: FontWeight.bold),
        ),
      );
  }
}