import 'package:flutter/material.dart';

import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:f0ckapp/providers/theme_provider.dart';
import 'package:f0ckapp/utils/appversion_util.dart';

class EndDrawer extends StatelessWidget {
  final WidgetRef ref;

  const EndDrawer({super.key, required this.ref});

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: [
          DrawerHeader(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/menu.webp'),
                fit: BoxFit.cover,
                alignment: Alignment.topCenter,
              ),
            ),
            child: null,
          ),
          /*ExpansionTile(
              title: const Text('Login'),
              children: [
                Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    children: [
                      TextField(
                        readOnly: true,
                        controller: _usernameController,
                        decoration: const InputDecoration(
                          labelText: 'Benutzername',
                        ),
                      ),
                      const SizedBox(height: 10),
                      TextField(
                        readOnly: true,
                        controller: _passwordController,
                        obscureText: true,
                        decoration: const InputDecoration(
                          labelText: 'Passwort',
                        ),
                      ),
                      const SizedBox(height: 20),
                      ElevatedButton(
                        onPressed: () async {
                          ScaffoldMessenger.of(context).showSnackBar(
                            const SnackBar(
                              content: Text("noch nicht implementiert lol"),
                            ),
                            final success = await login(
                              _usernameController.text,
                              _passwordController.text,
                            );

                            if (success) {
                              Navigator.pop(context);
                            } else {
                              ScaffoldMessenger.of(context).showSnackBar(
                                SnackBar(content: Text("Login fehlgeschlagen!")),
                              );
                            }
                          );
                        },
                        child: const Text('Login'),
                      ),
                    ],
                  ),
                ),
              ],
            ),*/
          ExpansionTile(
            title: const Text('Theme'),
            children: [
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 16.0),
                child: Column(
                  children: themeMap.entries.map((entry) {
                    final String themeName = entry.key;
                    final ThemeData themeData = entry.value;
                    final ThemeData currentTheme = ref.watch(
                      themeNotifierProvider,
                    );
                    final bool isSelected = currentTheme == themeData;
                    return ListTile(
                      title: Text(themeName),
                      selected: isSelected,
                      selectedTileColor: Colors.blue.withValues(alpha: 0.2),
                      onTap: () async {
                        await ref
                            .read(themeNotifierProvider.notifier)
                            .updateTheme(themeName);
                      },
                    );
                  }).toList(),
                ),
              ),
            ],
          ),
          ListTile(
            title: Text('v${AppVersion.version}'),
            onTap: () {
              ScaffoldMessenger.of(context).showSnackBar(
                const SnackBar(
                  content: Text('jooong lass das, hier ist nichts'),
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}
