import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/components/appbar.dart';
import 'package:vitalapp/components/side_nav/defines.dart';
import 'package:vitalapp/components/side_nav/side_nav.dart';
import 'package:vitalapp/pages/home/personal_center/controller.dart';
import 'package:vitalapp/pages/home/personal_center/widgets/avatar.dart';
import 'package:vitalapp/pages/home/personal_center/widgets/info.dart';
import 'package:vitalapp/pages/home/personal_center/widgets/password.dart';
import 'package:vitalapp/pages/home/personal_center/widgets/signature.dart';

class PersonalCenterPage extends GetView<PersonalCenterController> {
  const PersonalCenterPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: VAppBar(
          titleWidget: const Text(
            '个人中心',
            style: TextStyle(
              fontSize: 24,
            ),
          ),
        ),
        body: Stack(
          children: [
            VSideNavView(
              items: _buildItems(),
            ),
            // Positioned(
            //   bottom: 8,
            //   left: 200,
            //   right: 200,
            //   child: Row(
            //     mainAxisAlignment: MainAxisAlignment.spaceAround,
            //     children: [
            //       VButton(
            //         label: "下一步",
            //         onTap: () {
            //           Get.back();
            //         },
            //       ),
            //     ],
            //   ),
            // ),
          ],
        )
        // Obx(
        //   () => Container(
        //     padding: const EdgeInsets.all(16),
        //     child: Row(
        //       children: [
        //         Expanded(
        //           flex: 1,
        //           child: Center(
        //             child: Image.asset(
        //               "assets/images/exam/21.png",
        //               fit: BoxFit.cover,
        //             ),
        //           ),
        //         ),
        //         Expanded(
        //           flex: 1,
        //           child: Column(
        //             children: [
        //               topInfo(context),
        //               commonFunction(),
        //             ],
        //           ),
        //         ),
        //       ],
        //     ),
        //   ),
        // ),
        );
  }

  List<VSideNavMenuItem> _buildItems() {
    final items = <VSideNavMenuItem>[];
    items.add(_buildInfoItem());
    items.add(_buildAvatarItem());
    items.add(_buildPasswordItem());
    items.add(_buildSignatureItem());
    return items;
  }

  VSideNavMenuItem _buildAvatarItem() {
    return VSideNavMenuItem(
      title: '头像',
      icon: Icon(
        Icons.edit_document,
        color: Colors.grey.shade700,
      ),
      pageBuilder: (_) => const AvatarPage(),
    );
  }

  VSideNavMenuItem _buildInfoItem() {
    return VSideNavMenuItem(
      title: '基本信息',
      icon: Icon(
        Icons.edit_document,
        color: Colors.grey.shade700,
      ),
      pageBuilder: (_) => const InfoPage(),
    );
  }

  VSideNavMenuItem _buildPasswordItem() {
    return VSideNavMenuItem(
      title: '修改密码',
      icon: Icon(
        Icons.edit_document,
        color: Colors.grey.shade700,
      ),
      pageBuilder: (_) => const PasswordPage(),
    );
  }

  VSideNavMenuItem _buildSignatureItem() {
    return VSideNavMenuItem(
      title: '签名设置',
      icon: Icon(
        Icons.edit_document,
        color: Colors.grey.shade700,
      ),
      pageBuilder: (_) => const SignaturePage(),
    );
  }

  Padding topInfo(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(30, 10, 10, 40),
      child: Row(
        children: [
          GestureDetector(
            child: ClipOval(
              child: Image.asset('assets/images/avatar.png'),
            ),
            onTap: () {},
          ),
          Padding(
            padding: const EdgeInsets.fromLTRB(16, 0, 150, 0),
            child: Text(
              controller.state.dto.realName ?? '',
              style: const TextStyle(
                fontWeight: FontWeight.w600,
                fontSize: 16,
              ),
            ),
          ),
          TextButton(
            onPressed: () {},
            style: ButtonStyle(
              minimumSize: MaterialStateProperty.all(
                const Size(80, 60),
              ),
              foregroundColor: MaterialStateProperty.all<Color>(
                  const Color.fromARGB(100, 30, 144, 255)),
              shape: MaterialStateProperty.all(
                RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(
                    10,
                  ),
                ),
              ),
            ),
            child: const Text(
              '编辑资料',
              style: TextStyle(color: Colors.blueAccent),
            ),
          )
        ],
      ),
    );
  }
}
