import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/components/cell.dart';
import 'package:vitalapp/components/dialog_input.dart';
import 'package:vitalapp/pages/patient/create/controller.dart';

class Address extends GetView<CreatePatientController> {
  const Address({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        VListFormCellGroup(
          children: [
            VListFormCell(
              label: "同步户籍地址到现住地址",
              labelWidth: 250,
              contentWidget: Container(
                child: Obx(
                  () => Switch(
                    onChanged: (value) {
                      controller.onSyncAddressCheckChanged(value);
                    },
                    value: controller.state.isSyncAddresses,
                  ),
                ),
              ),
            ),
            Obx(
              () => VListFormCell(
                label: "户籍地址",
                content: controller.state.censusRegister,
                onTap: () async {
                  final result = await VDialogInput(
                    title: "户籍地址",
                    initialValue: controller.state.censusRegister,
                    placeholder: "请填写户籍地址",
                  ).show();
                  if (result != null) {
                    controller.onCensusRegisterChanged(result);
                  }
                },
              ),
            ),
            Obx(
              () => VListFormCell(
                label: "现住地址",
                content: controller.state.address,
                onTap: () async {
                  final result = await VDialogInput(
                    title: "现住地址",
                    initialValue: controller.state.address,
                    placeholder: "请填写现住地址",
                  ).show();
                  if (result != null) {
                    controller.state.address = result;
                  }
                },
              ),
            ),
          ],
        ),
      ],
    );
  }
}
