import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/managers/interfaces/entities/consultation_member.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/controller.dart';
import 'package:get/get.dart';

class PreviewMemberStatus extends FStatelessWidget {
  final ConsultationMember member;
  final controller = Get.find<LiveConsultationController>();
  static final double _smallLivePreviewHeight = kIsMobile ? 100 : 190;
  static final TextStyle _previewMemberTextStyle =
      TextStyle(color: Colors.grey);
  static final double _previewMemberHeadTitle = kIsMobile ? 0 : 30;
  PreviewMemberStatus(this.member);
  @override
  FWidget build(BuildContext context) {
    return FObx(() {
      var status = controller.state.memberStatus;
      if (status.containsKey(member.id)) {
        var consultationMember = status[member.id];
        if (member.mergedChannel) {
          return FSizedBox();
        }
        switch (consultationMember!.status) {
          case MemberStatus.Calling:
            return _buildCallingText(i18nBook.realTimeConsultation.calling.t);
          case MemberStatus.Rejected:
            return _buildCallingText(i18nBook.realTimeConsultation.rejected.t);
          case MemberStatus.Left:
            return _buildCallingText(i18nBook.realTimeConsultation.hasLeft.t);
          case MemberStatus.Busyline:
            return _buildCallingText(i18nBook.realTimeConsultation.busy.t);
          case MemberStatus.Offline:
            return _buildCallingText(i18nBook.user.notOnline.t);
          case MemberStatus.Cancel:
            return _buildCallingText(
                i18nBook.realTimeConsultation.callCanceled.t);
          case MemberStatus.NetError:
            return _buildCallingText(i18nBook.common.networkInstability.t);
          default:
            return FSizedBox();
        }
      }
      return FSizedBox();
    });
  }

  ///呼叫中蒙层显示
  FWidget _buildCallingText(String content) {
    return FPositioned(
      left: 0,
      right: 0,
      top: _previewMemberHeadTitle,
      child: FContainer(
        height: _smallLivePreviewHeight,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            colors: [
              Colors.black.withOpacity(0.7),
              Colors.black.withOpacity(0.7),
            ],
            begin: Alignment.bottomCenter,
            end: Alignment.topCenter,
          ),
        ),
        child: FText(
          content,
          style: _previewMemberTextStyle,
        ),
      ),
    );
  }
}
