import 'package:fis_jsonrpc/rpc.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vnoteapp/components/date_picker.dart';
import 'package:vnoteapp/components/input.dart';
import 'package:vnoteapp/components/select.dart';
import 'package:vnoteapp/consts/nations.dart';
import 'package:vnoteapp/consts/rpc_enum_labels.dart';
import 'package:vnoteapp/pages/patient/info/controller.dart';

import '../../../../components/form.dart';

class PatientInfoBaseView extends GetView<PatientInfoController> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 48, vertical: 24),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildRow(_buildName(), _buildGender()),
          _buildRow(_buildNation(), _buildCardType()),
          _buildRow(_buildCardNo(), _buildBirthday()),
          _buildRow(_buildAddress(), _buildCreateOrg()),
          _buildRow(_buildCensusRegister(), _buildCreator()),
          _buildRow(_buildTown(), _buildContractDoctor()),
          _buildRow(_buildVillage(), _buildCreateDate()),
        ],
      ),
    );
  }

  Widget _buildRow(Widget childLeft, Widget? childRight) {
    return Container(
      height: 50,
      width: 840,
      alignment: Alignment.centerLeft,
      // padding: EdgeInsets.symmetric(horizontal: 2),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          childLeft,
          childRight ?? const SizedBox(),
        ],
      ),
    );
  }

  Widget _buildName() {
    return VFormCell(
      label: "姓名：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          placeholder: "请输入姓名",
          // initialValue: controller.state.,
          initialValue: "testlabel",
        ),
      ),
    );
  }

  Widget _buildGender() {
    return VFormCell(
      label: "性别：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VSelect<GenderEnum, GenderEnum>(
          source: const [
            GenderEnum.Male,
            GenderEnum.Female,
            GenderEnum.Unknown,
            GenderEnum.Unspecified
          ],
          value: GenderEnum.Male,
          labelGetter: (e) => RpcEnumLabels.gender[e]!,
          valueGetter: (e) => e,
          onChanged: (value) {
            // controller.state.gender = value;
          },
        ),
      ),
    );
  }

  Widget _buildNation() {
    return VFormCell(
      label: "民族：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VSelect<String, String>(
          source: Nations.china,
          value: Nations.china.first,
          labelGetter: (e) => e,
          valueGetter: (e) => e,
          onChanged: (value) {
            // controller.state.nation = value;
          },
        ),
      ),
    );
  }

  Widget _buildCardType() {
    return VFormCell(
      label: "证件类型：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VSelect<CardTypeEnum, CardTypeEnum>(
          source: CardTypeEnum.values,
          value: CardTypeEnum.Identity,
          labelGetter: (e) => RpcEnumLabels.cardType[e]!,
          valueGetter: (e) => e,
          onChanged: (value) {
            // controller.state.cardType = value;
          },
        ),
      ),
    );
  }

  Widget _buildCardNo() {
    return VFormCell(
      label: "证件号码：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          placeholder: "请输入证件号码",
          initialValue: "320506200001011211",
        ),
      ),
    );
  }

  Widget _buildBirthday() {
    return VFormCell(
      label: "出生日期：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VDatePicker(
          value: DateTime(2000, 1, 1),
          onChanged: (value) {
            // controller.state.birthday = value;
          },
        ),
      ),
    );
  }

  Widget _buildAddress() {
    return VFormCell(
      label: "现住地址：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          placeholder: "请输入现住地址",
          initialValue: "苏州市斜塘街道xxx",
        ),
      ),
    );
  }

  Widget _buildCensusRegister() {
    return VFormCell(
      label: "户籍地址：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          placeholder: "请输入户籍地址",
          initialValue: "苏州市斜塘街道xxx",
        ),
      ),
    );
  }

  Widget _buildTown() {
    return VFormCell(
      label: "乡镇/街道：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          placeholder: "请输入乡镇/街道",
          initialValue: "斜塘街道",
        ),
      ),
    );
  }

  Widget _buildVillage() {
    return VFormCell(
      label: "村(居委会)：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          placeholder: "请输入村(居委会)",
          initialValue: "Vinno村",
        ),
      ),
    );
  }

  Widget _buildCreateOrg() {
    return VFormCell(
      label: "建档单位：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          initialValue: "Vinno医院",
        ),
      ),
    );
  }

  Widget _buildCreator() {
    return VFormCell(
      label: "建档人：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          initialValue: "melon",
        ),
      ),
    );
  }

  Widget _buildCreateDate() {
    return VFormCell(
      label: "建档日期：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          initialValue: "2023-09-09 15:30:25",
        ),
      ),
    );
  }

  Widget _buildContractDoctor() {
    return VFormCell(
      label: "责任医生：",
      child: SizedBox(
        width: 200,
        height: 38,
        child: VInput(
          // placeholder: "请输入姓名",
          initialValue: "Mike",
        ),
      ),
    );
  }
}
