import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/providers/theme_provider.dart';
import 'package:didvan/providers/user_provider.dart';
import 'package:didvan/routes/routes.dart';
import 'package:didvan/services/storage/storage.dart';
import 'package:didvan/views/home/widgets/logo_app_bar.dart';
import 'package:didvan/views/home/widgets/menu_item.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/divider.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:didvan/views/widgets/item_title.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';

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

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      padding: const EdgeInsets.all(16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Consumer<ThemeProvider>(
            builder: (context, themeProvider, child) => LogoAppBar(
              hasExtraPadding: false,
              key: UniqueKey(),
            ),
          ),
          const SizedBox(height: 16),
          DidvanCard(
            child: Column(
              children: [
                MenuItem(
                  title: 'پیام‌ها',
                  icon: DidvanIcons.message_regular,
                  onTap: () =>
                      Navigator.of(context).pushNamed(Routes.directList),
                ),
                const DidvanDivider(),
                MenuItem(
                  title: 'ویرایش پروفایل',
                  icon: DidvanIcons.user_edit_regular,
                  suffix: context.read<UserProvider>().user.fullName,
                  onTap: () => Navigator.of(context).pushNamed(Routes.profile),
                ),
                const DidvanDivider(),
                MenuItem(
                  title: 'تنظیمات',
                  icon: DidvanIcons.setting_regular,
                  onTap: () =>
                      Navigator.of(context).pushNamed(Routes.generalSettings),
                ),
                const DidvanDivider(),
                MenuItem(
                  title: 'نشان شده‌ها',
                  icon: DidvanIcons.bookmark_regular,
                  onTap: () =>
                      Navigator.of(context).pushNamed(Routes.bookmarks),
                ),
                const DidvanDivider(),
                MenuItem(
                  title: 'خروج از حساب کاربری',
                  icon: DidvanIcons.sign_out_regular,
                  color: Theme.of(context).colorScheme.secondary,
                  onTap: () async {
                    StorageService.delete(key: 'token');
                    Navigator.of(context).pushNamedAndRemoveUntil(
                      Routes.splash,
                      (_) => false,
                    );
                  },
                ),
              ],
            ),
          ),
          const ItemTitle(
            title: 'درباره ما',
            icon: DidvanIcons.info_circle_regular,
          ),
          DidvanCard(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                MenuItem(
                  icon: DidvanIcons.didvan_solid,
                  title: 'معرفی دیدوان',
                  onTap: () => launch('https://didvan.app/'),
                ),
                const DidvanDivider(),
                MenuItem(
                  icon: DidvanIcons.support_regular,
                  title: 'پیام به پشتیبانی',
                  onTap: () {
                    launch('mailto:info@didvan.app');
                  },
                ),
                const DidvanDivider(),
                MenuItem(
                  icon: DidvanIcons.alert_regular,
                  title: 'حریم خصوصی',
                  onTap: () => launch('https://didvan.app/'),
                ),
              ],
            ),
          ),
          const SizedBox(height: 16),
          DidvanText(
            'نسخه نرم‌افزار: 1.1.4',
            style: Theme.of(context).textTheme.caption,
          ),
        ],
      ),
    );
  }
}
