import 'package:chat/routes/user_routes.dart';
import 'package:chat/services/auth_service.dart';
import 'package:chat/views/user/widgets/link_action_item.dart';
import 'package:chat/widgets/custom_avatar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class UserInfoPage extends StatefulWidget {
  const UserInfoPage({Key? key}) : super(key: key);

  @override
  State<UserInfoPage> createState() => _UserInfoPageState();
}

class _UserInfoPageState extends State<UserInfoPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('个人资料'),
      ),
      body: GetX<AuthService>(
        builder: (_) {
          return Column(
            children: [
              LinkActionItem(
                title: '头像',
                onTap: () async {
                  Get.toNamed(UserRoutes.infoAvatar);
                },
                isLink: true,
                trailing: CustomAvatar(
                  _.userInfo.value.avatar,
                  size: 52,
                ),
              ),
              LinkActionItem(
                title: '昵称',
                trailing: Text(_.userInfo.value.nickname!),
                isLink: true,
                onTap: () {
                  Get.toNamed(
                    UserRoutes.infoNickname,
                    arguments: {
                      'nickname': _.userInfo.value.nickname,
                    },
                  );
                },
              ),
            ],
          );
        },
      ),
    );
  }
}
