import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'app_state.dart';
import 'favorite_page.dart';
import 'swipe_page.dart';
import 'about_page.dart';


void main() => runApp(const TindCode());


class TindCode extends StatelessWidget {
  const TindCode({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) {
        final appState = TindCodeState();
        appState.loadData();
        return appState;
      },
      child: MaterialApp(
        theme: ThemeData(
          primarySwatch: Colors.blue,
          primaryColor: Color.fromRGBO(212, 163, 115, 1),
          backgroundColor: Color.fromRGBO(233, 237, 201, 1),
          scaffoldBackgroundColor: Color.fromRGBO(254, 250, 224, 1),
          appBarTheme: AppBarTheme(
            backgroundColor: Color.fromRGBO(212, 163, 115, 1), // Set app bar color
          ),
          navigationRailTheme: NavigationRailThemeData(
            backgroundColor: Color.fromRGBO(212, 163, 115, 1), // Set navigation rail color
          ),
        ),
        title: 'Tind Code',
        home: Scaffold(
          appBar: AppBar(title: Text(
            'Tind Code',
            style: TextStyle(
              fontSize: 24,
              fontWeight: FontWeight.bold,
              letterSpacing: 1.5,
            ),
          ),),
          body: const MyHomePage(),
        ),
      ),
    );
  }
}


class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    Widget page;
    switch (selectedIndex) {
      case 0:
        page = FavoritePage();
        break;
      case 1:
        page = TindCodeContent();
        break;
      case 2:
        page = AboutPage();
        break;
      default:
        throw UnimplementedError('no widget for $selectedIndex');
    }

    return LayoutBuilder(
      builder: (context, constraints) => Scaffold(
        body: Row(children: [
          SafeArea(child: NavigationRail(
            extended: constraints.maxWidth >= 600,
            destinations: [
              NavigationRailDestination(
                icon: Icon(Icons.home),
                label: Text(
                  'Home',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.swipe),
                label: Text(
                  'Swipe',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.info),
                label: Text(
                  'About',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ],
            selectedIndex: selectedIndex,
            onDestinationSelected: (value) {
              print('selected: $value');
              setState(() {
                selectedIndex = value;
              });
            },
          ),),
          VerticalDivider(
            thickness: 1,
            width: 1,
          ), // Add a vertical divider
          Expanded(child: Container(
            color: Color.fromRGBO(250, 237, 205, 1),
            child: page,
          )),
        ],),
      )
    );
  }
}
