import 'package:fis_i18n/i18n.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/pages/remedical/consultation/controller.dart';

class ConfirmReferralDialog extends FisView<ConsultationController> {
  final String referralRecordCode;
  const ConfirmReferralDialog({
    Key? key,
    required this.referralRecordCode,
  }) : super(key: key);

  @override
  FWidget build(BuildContext context) {
    return FSimpleDialog(
      title: FText(
        i18nBook.user.refuse.t,
        style: TextStyle(
          color: Colors.white,
          fontSize: 18,
        ),
      ),
      children: [
        FContainer(
          width: 500,
          child: FContainer(
            margin: EdgeInsets.symmetric(horizontal: 30),
            child: FColumn(
              children: [
                _buildReferralItem(
                  i18nBook.user.refuseReason.t,
                  FTextField(
                    maxLines: 3,
                    decoration: InputDecoration(
                      hintText: i18nBook.common.input
                          .translate([i18nBook.user.refuseReason.t]),
                      hintStyle: TextStyle(
                        fontSize: 16,
                      ),
                      enabledBorder: OutlineInputBorder(
                        borderSide: BorderSide(
                          color: Colors.white.withOpacity(0.5),
                          width: 0.5,
                          style: BorderStyle.solid,
                        ),
                      ),
                      focusedBorder: OutlineInputBorder(
                        borderSide: BorderSide(
                          color: FTheme.ins.colorScheme.primary,
                          width: 0.5,
                          style: BorderStyle.solid,
                        ),
                      ),
                      filled: true,
                    ),
                    controller: TextEditingController(
                      text: controller.state.refuseCause,
                    ),
                    onChanged: (val) => controller.state.refuseCause = val,
                  ),
                  true,
                ),
              ],
            ),
          ),
        ),
      ],
      isDefault: true,
      onOk: () {
        controller.inspectionRecordsController.auditReferralRecordAsync(
          referralRecordCode,
          false,
        );
      },
      okString: i18nBook.common.confirm.t,
      cancelString: i18nBook.common.cancel.t,
      onCancel: () {
        controller.state.refuseCause = '';
        router.back();
      },
    );
  }

  FWidget _buildReferralItem(String title, FWidget referralItem,
      [bool? isRequired]) {
    return FContainer(
      margin: EdgeInsets.symmetric(
        vertical: 15,
      ),
      child: FRow(
        children: [
          FContainer(
            width: 120,
            child: FRow(
              children: [
                FText(title),
                isRequired ?? false
                    ? FText(
                        '*',
                        style: TextStyle(color: Colors.red),
                      )
                    : FSizedBox(),
              ],
            ),
          ),
          FExpanded(
            child: referralItem,
          ),
        ],
      ),
    );
  }
}
