// import 'package:cheminova/provider/home_provider.dart';
// import 'package:cheminova/screens/change_password_screen.dart';
// import 'package:cheminova/screens/home_screen.dart';
// import 'package:cheminova/screens/login_screen.dart';
// import 'package:cheminova/screens/profile_screen.dart';
// import 'package:cheminova/services/secure__storage_service.dart';
// import 'package:flutter/material.dart';
// import 'package:provider/provider.dart';
//
// class CommonDrawer extends StatelessWidget {
//   const CommonDrawer({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     return Drawer(
//       child: ListView(
//         padding: EdgeInsets.zero,
//         children: <Widget>[
//           SizedBox(
//               height: 150,
//               child: DrawerHeader(
//                   decoration: const BoxDecoration(
//                     color: Colors.black87,
//                   ),
//                   child: Consumer<HomeProvider>(
//                       builder: (context, value, child) =>
//                           (value.profileResponse == null ||
//                                   value.profileResponse!.myData == null ||
//                                   value.profileResponse!.myData!.name == null)
//                               ? const SizedBox()
//                               : Column(
//                                   crossAxisAlignment: CrossAxisAlignment.start,
//                                   mainAxisAlignment: MainAxisAlignment.start,
//                                   children: [
//                                       Text(value.profileResponse!.myData!.name!,
//                                           style: const TextStyle(
//                                               color: Colors.white,
//                                               fontSize: 18)),
//                                       Text(value.profileResponse!.myData!.uniqueId!,
//                                           style: const TextStyle(
//                                               color: Colors.white,
//                                               fontSize: 15))
//                                     ])))),
//           ListTile(
//               leading: const Icon(Icons.home),
//               title: const Text('Home'),
//               onTap: () => Navigator.push(context,
//                   MaterialPageRoute(builder: (context) => const HomePage()))),
//           ListTile(
//             leading: const Icon(Icons.person),
//             title: const Text('Profile'),
//             onTap: () {
//               Navigator.push(
//                   context,
//                   MaterialPageRoute(
//                     builder: (context) => const ProfileScreen(),
//                   ));
//             },
//           ),
//           ListTile(
//             leading: const Icon(Icons.settings),
//             title: const Text('Change Password'),
//             onTap: () {
//               Navigator.push(
//                   context,
//                   MaterialPageRoute(
//                     builder: (context) => const ChangePasswordPage(),
//                   ));
//             },
//           ),
//           ListTile(
//             leading: const Icon(Icons.exit_to_app),
//             title: const Text('Logout'),
//             onTap: () {
//               Provider.of<HomeProvider>(context,listen: false).logOut(context);
//
//             },
//           ),
//         ],
//       ),
//     );
//   }
// }



import 'package:cheminova/provider/home_provider.dart';
import 'package:cheminova/screens/change_password_screen.dart';
import 'package:cheminova/screens/home_screen.dart';
import 'package:cheminova/screens/login_screen.dart';
import 'package:cheminova/screens/profile_screen.dart';
import 'package:cheminova/services/secure__storage_service.dart';
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';

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

  @override
  State<CommonDrawer> createState() => _CommonDrawerState();
}

class _CommonDrawerState extends State<CommonDrawer> {



  String _appVersion = '';

  @override
  void initState() {
    super.initState();
    _getAppVersion();
  }

  Future<void> _getAppVersion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform(

    );
    setState(() {
      _appVersion = packageInfo.version; // 1.0.0
    });
  }

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(
        children: <Widget>[
          SizedBox(
              height: 150,
              width:double.infinity,
              child: DrawerHeader(
                  decoration: const BoxDecoration(
                    color: Colors.black87,
                  ),
                  child: Consumer<HomeProvider>(
                      builder: (context, value, child) =>
                      (value.profileResponse == null ||
                          value.profileResponse!.myData == null ||
                          value.profileResponse!.myData!.name == null)
                          ? const SizedBox()
                          : Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Text(value.profileResponse!.myData!.name!,
                                style: const TextStyle(
                                    color: Colors.white,
                                    fontSize: 18)),
                            Text(value.profileResponse!.myData!.uniqueId!,
                                style: const TextStyle(
                                    color: Colors.white,
                                    fontSize: 15))
                          ])))),

          // Drawer List Items
          ListTile(
              leading: const Icon(Icons.home),
              title: const Text('Home'),
              onTap: () => Navigator.push(context,
                  MaterialPageRoute(builder: (context) => const HomePage()))),
          ListTile(
            leading: const Icon(Icons.person),
            title: const Text('Profile'),
            onTap: () {
              Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const ProfileScreen(),
                  ));
            },
          ),
          ListTile(
            leading: const Icon(Icons.settings),
            title: const Text('Change Password'),
            onTap: () {
              Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const ChangePasswordPage(),
                  ));
            },
          ),
          ListTile(
            leading: const Icon(Icons.exit_to_app),
            title: const Text('Logout'),
            onTap: () {
              Provider.of<HomeProvider>(context, listen: false).logOut(context);
            },
          ),
          const Spacer(),
          // Version Text at the Bottom
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Center(
              child: Text(
                'Version: $_appVersion',
                style: TextStyle(color: Colors.grey[600], fontSize: 12),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
