import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:vitalapp/architecture/utils/prompt_box.dart';
import 'package:vitalapp/components/cell.dart';
import 'package:vitalapp/components/dialog_input.dart';
import 'package:vitalapp/pages/home/personal_center/controller.dart';

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

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        VListFormCellGroup(
          children: [
            Obx(
              () => VListFormCell(
                label: "姓名",
                content: controller.state.name,
                onTap: () async {
                  final result = await VDialogInput(
                    title: "姓名",
                    initialValue: controller.state.name,
                    placeholder: "请填写姓名",
                  ).show();
                  if (result != null) {
                    controller.state.name = result;
                    if (await controller.updateUserInfo()) {
                      PromptBox.toast("修改姓名成功");
                    }
                  }
                },
              ),
            ),
            Obx(
              () => VListFormCell(
                label: "手机号",
                content: controller.state.phone,
                onTap: () async {
                  final result = await VDialogInput(
                    title: "手机号",
                    initialValue: controller.state.phone,
                    placeholder: "请填写手机号",
                  ).show();
                  if (result != null) {
                    controller.state.phone = result;
                    if (await controller.updateUserInfo()) {
                      PromptBox.toast("修改手机号成功");
                    }
                  }
                },
              ),
            ),
            Obx(
              () => VListFormCell(
                label: "用户角色",
                content: controller.state.roleName,
              ),
            ),
            Obx(
              () => VListFormCell(
                label: "医院名称",
                content: controller.state.organizationName,
              ),
            ),
            Obx(
              () => VListFormCell(
                label: "团队名称",
                content: controller.state.teamName,
              ),
            ),
          ],
        ),
      ],
    );
  }
}
