import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vnoteapp/components/alert_dialog.dart';
import 'package:vnoteapp/components/side_nav/defines.dart';
import 'package:vnoteapp/components/side_nav/side_nav.dart';
import 'package:vnoteapp/pages/doctor/signature_setting/controller.dart';
import 'package:vnoteapp/pages/doctor/signature_setting/view.dart';
import 'package:vnoteapp/pages/settings/about/view.dart';
import 'package:vnoteapp/routes/nav_ids.dart';
import 'package:vnoteapp/routes/route_setting.dart';

import 'controller.dart';

class SettingCenterPage extends GetView<SettingCenterController> {
  const SettingCenterPage({super.key});

  @override
  Widget build(BuildContext context) {
    return VSideNavView(
      navId: NavIds.SETTINGS,
      items: _buildItems(),
    );
  }

  List<VSideNavMenuItem> _buildItems() {
    final items = <VSideNavMenuItem>[];
    items.add(_buildSignatureItem());
    items.add(_buildAboutItem());
    items.add(_buildLogOutItem());
    return items;
  }

  VSideNavMenuItem _buildSignatureItem() {
    return VSideNavMenuItem(
      title: "签名设置",
      icon: Icon(Icons.edit_document, color: Colors.grey.shade700),
      route: VRouteSetting(
        "/signature",
        () => const DoctorSignatureSettingPage(),
        binding: BindingsBuilder(
          () {
            Get.lazyPut(() => DoctorSignatureSettingController());
          },
        ),
      ),
    );
  }

  VSideNavMenuItem _buildAboutItem() {
    return VSideNavMenuItem(
      title: "关于我们",
      icon: Icon(Icons.info_outline, color: Colors.grey.shade700),
      route: VRouteSetting("/about", () => const AboutPage()),
    );
  }

  VSideNavMenuItem _buildLogOutItem() {
    return VSideNavMenuItem(
      title: "退出登录",
      icon: Icon(Icons.exit_to_app, color: Colors.grey.shade700),
      // shouldRearrage: true, // TODO: 调整样式后启用
      onTap: () {
        // TODO: 用confirm组件替换
        Get.dialog(
          VAlertDialog(
            title: "提示",
            width: 260,
            content: Container(
              height: 32,
              padding: const EdgeInsets.symmetric(horizontal: 24),
              alignment: Alignment.center,
              child: const Text(
                "确定退出登录？",
                style: TextStyle(fontSize: 20),
              ),
            ),
            onConfirm: () {
              controller.logOut();
            },
          ),
          barrierDismissible: false,
          barrierColor: Colors.black.withOpacity(.4),
        );
      },
    );
  }
}
