import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:sendtrain/database/database.dart';
import 'package:sendtrain/helpers/widget_helpers.dart';
import 'package:sendtrain/models/activity_timer_model.dart';
import 'package:sendtrain/providers/action_timer.dart';
import 'package:sendtrain/widgets/screens/activities_screen.dart';
import 'package:sendtrain/widgets/screens/sessions_screen.dart';
// ignore: unused_import
import 'package:sendtrain/database/seed.dart';
import 'package:sendtrain/widgets/sessions/session_editor.dart';

class SendTrain extends StatelessWidget {
  const SendTrain({super.key});

  @override
  Widget build(BuildContext context) {
    final ThemeData themeData = ThemeData.dark(useMaterial3: true);
    return MaterialApp(
        title: "Sendtrain",
        theme: themeData.copyWith(
          filledButtonTheme: FilledButtonThemeData(
            style: FilledButton.styleFrom(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(12),
              ),
            ),
          ),
          floatingActionButtonTheme: FloatingActionButtonThemeData(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(12))),
          inputDecorationTheme: InputDecorationTheme(
            fillColor: themeData.colorScheme.surface,
          ),
        ),
        home: const App());
  }
}

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  int currentPageIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // appBar: AppBar(
        //     toolbarOpacity: 0,
        //     centerTitle: true,
        //     title: const Text('SENDTRAIN'),
        //     scrolledUnderElevation: 0,
        //     actions: <Widget>[
        //       IconButton(
        //           // highlightColor: Colors.deepPurple,
        //           icon: const Icon(Icons.settings),
        //           tooltip: 'Application Settings',
        //           onPressed: () {})
        //     ]),
        body: Padding(
            padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
            child: <Widget>[
              SessionsScreen(),
              const ActivitiesScreen(),
              Container(
                alignment: Alignment.center,
                child: const Text('In Progress...'),
              ),
              Container(
                alignment: Alignment.center,
                child: const Text('In Progress...'),
              ),
              Container(
                alignment: Alignment.center,
                child: const Text('In Progress...'),
              ),
              Container(
                alignment: Alignment.center,
                child: const Text('Profile in Progress...'),
              ),
            ][currentPageIndex]),
        bottomNavigationBar: NavigationBar(
            onDestinationSelected: (int index) {
              setState(() {
                currentPageIndex = index;
              });
            },
            selectedIndex: currentPageIndex,
            destinations: const <Widget>[
              NavigationDestination(
                  icon: Icon(Icons.sports), label: "Sessions"),
              NavigationDestination(
                  icon: Icon(Icons.sports_gymnastics_rounded),
                  label: "Activities"),
              NavigationDestination(
                  icon: Icon(Icons.calendar_month_rounded), label: "Plan"),
              NavigationDestination(
                  icon: Icon(Icons.group), label: "Team Send"),
              NavigationDestination(
                  icon: Icon(Icons.analytics), label: "Progress"),
              NavigationDestination(
                  icon: Icon(Icons.account_circle_rounded), label: "Profile"),
            ]),
        floatingActionButton: FloatingActionButton.extended(
          onPressed: () {
            showEditorSheet(context, SessionEditor());
          },
          label: const Text('New Session'),
          icon: const Icon(Icons.add_chart),
          // backgroundColor: Colors.deepPurple,
        ));
  }
}

void main() {
  var db = AppDatabase();
  runApp(MultiProvider(
    providers: [
      Provider<AppDatabase>(
          create: (context) => db, dispose: (context, db) => db.close()),
      ChangeNotifierProvider(create: (context) => ActivityTimerModel()),
      ChangeNotifierProvider(create: (context) => ActionTimer()),
    ],
    child: const SendTrain(),
  ));
}
