
import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/router.dart';
import 'package:flyinsono/pages/consultation/controller.dart';
import 'package:get/get.dart';

import 'light_title.dart';
import 'line_patient_data.dart';

/// 新建随访记录
class AddFollowUpPage extends FisView<MobileConsultationController>
    implements FPage {
  @override
  String get pageName => 'FollowUpAddPage';

  @override
  FWidget build(BuildContext context) {
    var patientName =
        controller.state.currentConsultationDetail?.patientName ?? '';
    var patientDatas =
        controller.state.currentConsultationDetail?.patientDatas ?? [];
    var phone = patientDatas
        .firstWhereOrNull((element) => element.key == 'Phone')
        ?.value;
    return FScaffold(
      backgroundColor: Colors.grey[100],
      appBar: FAppBar.simple(
        title: i18nBook.common.add.t + i18nBook.realTimeConsultation.followUp.t,
        onBackClicked: () {
          router.back();
        },
      ),
      body: FContainer(
        child: FColumn(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            LightTitle(i18nBook.realTimeConsultation.patientInformation.t),
            //姓名
            LinePatientData(i18nBook.common.fullName.t, patientName),
            //手机号
            LinePatientData(i18nBook.common.mobileNumber.t, phone),
            LightTitle(i18nBook.realTimeConsultation.followUpRecord.t),

            FExpanded(
              child: _buildInputFollowUp(),
            ),
            _buildSubmitButton(phone, patientName),
          ],
        ),
      ),
    );
  }

  FWidget _buildSubmitButton(String? phone, String patientName) {
    return FContainer(
      height: 50,
      child: FRow(
        children: [
          FExpanded(
            child: FSizedBox(
              height: 50,
              child: FElevatedButton(
                businessParent: this,
                name: 'submit follow up',
                child: FText(
                  i18nBook.common.submit.t,
                  style: TextStyle(fontSize: 20),
                ),
                onPressed: () {
                  controller.submitFollowUp(phone, patientName);
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  /// 随访输入栏
  FWidget _buildInputFollowUp() {
    return FContainer(
      color: Colors.white,
      padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
      child: FTextField(
        maxLines: 10,
        minLines: 6,
        maxLength: 500,
        decoration: InputDecoration(
          border: OutlineInputBorder(borderRadius: BorderRadius.circular(8.0)),
          hintText: '',
          hintStyle: TextStyle(color: Colors.grey),
          hintMaxLines: 3,
        ),
        controller: controller.followUpController,
      ),
    );
  }
}
