import 'package:get/get.dart';
import 'package:vnoteapp/architecture/defines.dart';
import 'package:vnoteapp/managers/interfaces/patient.dart';

import 'state.dart';

class PatientDetailController extends FControllerBase {
  final _patientManager = Get.find<IPatientManager>();
  final state = PatientDetailState();

  @override
  void onInit() {
    final p = Get.parameters;
    state.code = p["code"]!;
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
    _loadData();
  }

  /// 打开信息页
  void gotoInfo() {
    Get.toNamed(
      "/patient/info",
      parameters: {"code": "1111"},
    );
  }

  Future<void> _loadData() async {
    final dto = await _patientManager.getDetail(state.code);
    if (dto != null) {
      dto.birthday = dto.birthday!.toLocal();
      state.updateDto(dto);
    }
  }
}
