import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_ui/values/font_sizes.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/architecture/utils/prompt_box.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/controller/real_time_consultation_controller.dart';
import 'package:fis_theme/theme.dart';

/// 受邀的第三方拒绝邀请
class ThirdPartRefusePage extends FisView<RealTimeConsultationController>
    implements FPage {
  const ThirdPartRefusePage({required this.controller, Key? key})
      : super(key: key);

  final RealTimeConsultationController controller;
  @override
  String get pageName => 'ThirdPartRefusePage';
  FWidget build(BuildContext context) {
    return _desktopLayout(this, controller);
  }

  FWidget _desktopLayout(
      FPage businessParent, RealTimeConsultationController controller) {
    return FSimpleDialog(
      title: FText(
        // i18nBook.realTimeConsultation.rejectApplication.t,
        i18nBook.realTimeConsultation.declineInvitation.t,
        style: TextStyle(
          color: Colors.white,
          fontSize: FFontSizes.H5,
        ),
      ),
      backgroundColor: Color.fromRGBO(230, 230, 230, 1),
      children: [
        FContainer(
          padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
          color: Colors.white,
          width: 500,
          child: FFlex(
            direction: Axis.horizontal,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              FExpanded(
                child: FContainer(
                  height: 100,
                  child: FRichText(
                    text: TextSpan(children: [
                      TextSpan(
                        text: i18nBook.realTimeConsultation.reasonsForRefusal.t,
                        style: TextStyle(
                          fontSize: FFontSizes.H6,
                          color: Colors.black,
                          fontFamily: FTheme.ins.localeSetting.fontFamily,
                        ),
                      ),
                      TextSpan(
                        text: "*",
                        style: TextStyle(
                            fontSize: FFontSizes.H6, color: Colors.red),
                      ),
                    ]),
                  ),
                ),
                flex: 1,
              ),
              FExpanded(
                child: FContainer(
                  height: 150,
                  child: FTextField(
                    maxLines: 5,
                    maxLength: 100,
                    onChanged: (value) =>
                        controller.state.refuseReason = value.trim(),
                    controller: controller.state.reasonController,
                    decoration: InputDecoration(
                      border: OutlineInputBorder(),
                    ),
                  ),
                ),
                flex: 3,
              ),
            ],
          ),
        ),
      ],
      isDefault: true,
      okString: i18nBook.common.confirm.t,
      cancelString: i18nBook.common.cancel.t,
      onOk: () {
        if (controller.state.refuseReason == "" ||
            controller.state.refuseReason == null) {
          PromptBox.toast(i18nBook.realTimeConsultation.reasonsCannotBeNull.t);
        } else {
          controller.refuseInvitation(controller.state.refuseReason!);
          router.back();
          controller.state.reasonController.clear();
        }
      },
      onClose: () {
        router.back(result: {'isCancel': true});
      },
      onCancel: () {
        router.back(result: {'isCancel': true});
        controller.state.reasonController.clear();
      },
    );
  }
}
